PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/DeviceCode/Targets/Native/STM32/ManagedCode/Hardware/HardwareProvider.cs

https://bitbucket.org/CW2/netduinofirmware
C# | 86 lines | 68 code | 6 blank | 12 comment | 2 complexity | 8c7f909862bc9995b887167ef5d62901 MD5 | raw file
Possible License(s): Apache-2.0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Copyright (c) Microsoft Corporation. All rights reserved.
  8. // Implementation for STM32: Copyright (c) Oberon microsystems, Inc.
  9. //
  10. // class Microsoft.SPOT.Hardware.STM32.STM32HardwareProvider
  11. //
  12. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. using System;
  14. using System.Threading;
  15. using System.Runtime.CompilerServices;
  16. using Microsoft.SPOT.Hardware;
  17. namespace Microsoft.SPOT.Hardware.STM32
  18. {
  19. internal class STM32HardwareProvider : HardwareProvider
  20. {
  21. static STM32HardwareProvider()
  22. {
  23. Microsoft.SPOT.Hardware.HardwareProvider.Register(new STM32HardwareProvider());
  24. }
  25. override public void GetSerialPins(string comPort, out Cpu.Pin rxPin, out Cpu.Pin txPin, out Cpu.Pin ctsPin, out Cpu.Pin rtsPin)
  26. {
  27. switch (comPort)
  28. {
  29. case "COM1":
  30. rxPin = Pins.GPIO_PIN_A_10;
  31. txPin = Pins.GPIO_PIN_A_9;
  32. ctsPin = Pins.GPIO_PIN_A_11;
  33. rtsPin = Pins.GPIO_PIN_A_12;
  34. break;
  35. case "COM2":
  36. rxPin = Pins.GPIO_PIN_A_3;
  37. txPin = Pins.GPIO_PIN_A_2;
  38. ctsPin = Pins.GPIO_PIN_A_0;
  39. rtsPin = Pins.GPIO_PIN_A_1;
  40. break;
  41. case "COM3":
  42. rxPin = Pins.GPIO_PIN_B_11;
  43. txPin = Pins.GPIO_PIN_B_10;
  44. ctsPin = Pins.GPIO_PIN_B_13;
  45. rtsPin = Pins.GPIO_PIN_B_14;
  46. break;
  47. default:
  48. throw new NotSupportedException();
  49. }
  50. }
  51. override public void GetI2CPins( out Cpu.Pin scl, out Cpu.Pin sda )
  52. {
  53. scl = Pins.GPIO_PIN_B_6;
  54. sda = Pins.GPIO_PIN_B_7;
  55. }
  56. override public void GetSpiPins( SPI.SPI_module spi_mod, out Cpu.Pin msk, out Cpu.Pin miso, out Cpu.Pin mosi )
  57. {
  58. switch (spi_mod)
  59. {
  60. case SPI.SPI_module.SPI1:
  61. msk = Pins.GPIO_PIN_A_5;
  62. miso = Pins.GPIO_PIN_A_6;
  63. mosi = Pins.GPIO_PIN_A_7;
  64. break;
  65. case SPI.SPI_module.SPI2:
  66. msk = Pins.GPIO_PIN_B_13;
  67. miso = Pins.GPIO_PIN_B_14;
  68. mosi = Pins.GPIO_PIN_B_15;
  69. break;
  70. case SPI.SPI_module.SPI3:
  71. msk = Pins.GPIO_PIN_B_3;
  72. miso = Pins.GPIO_PIN_B_4;
  73. mosi = Pins.GPIO_PIN_B_5;
  74. break;
  75. default:
  76. throw new NotSupportedException();
  77. }
  78. }
  79. }
  80. }