You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
1.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "chip.h"
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. uint8_t g_port_exit_critical_count;
  6. // NVIC_EnableIRQ
  7. // NVIC_GetEnableIRQ
  8. // NVIC_DisableIRQ
  9. void chip_critical_enter(void) {
  10. if (g_port_exit_critical_count == 0) {
  11. __disable_irq();
  12. // NVIC_DisableIRQ();
  13. }
  14. g_port_exit_critical_count++;
  15. }
  16. void chip_critical_exit(void) {
  17. g_port_exit_critical_count--;
  18. if (g_port_exit_critical_count == 0) {
  19. // NVIC_EnableIRQ();
  20. __enable_irq();
  21. }
  22. }
  23. GPIO_TypeDef* chip_get_gpio(Pin_t pin) {
  24. int port = pin >> 4;
  25. switch (port) {
  26. case 1:
  27. #ifdef GPIOA
  28. return GPIOA;
  29. #endif
  30. break;
  31. case 2:
  32. #ifdef GPIOB
  33. return GPIOB;
  34. #endif
  35. break;
  36. case 3:
  37. #ifdef GPIOC
  38. return GPIOC;
  39. #endif
  40. break;
  41. case 4:
  42. #ifdef GPIOD
  43. return GPIOD;
  44. #endif
  45. break;
  46. case 5:
  47. #ifdef GPIOE
  48. return GPIOE;
  49. #endif
  50. break;
  51. case 6:
  52. #ifdef GPIOF
  53. return GPIOF;
  54. #endif
  55. break;
  56. case 7:
  57. #ifdef GPIOG
  58. return GPIOG;
  59. #endif
  60. break;
  61. default:
  62. break;
  63. }
  64. return NULL;
  65. }
  66. uint16_t chip_get_pinoff(Pin_t pin) {
  67. uint16_t pinoff = pin & 0x0F;
  68. switch (pinoff) {
  69. case 0:
  70. return GPIO_PIN_0;
  71. case 1:
  72. return GPIO_PIN_1;
  73. case 2:
  74. return GPIO_PIN_2;
  75. case 3:
  76. return GPIO_PIN_3;
  77. case 4:
  78. return GPIO_PIN_4;
  79. case 5:
  80. return GPIO_PIN_5;
  81. case 6:
  82. return GPIO_PIN_6;
  83. case 7:
  84. return GPIO_PIN_7;
  85. case 8:
  86. return GPIO_PIN_8;
  87. case 9:
  88. return GPIO_PIN_9;
  89. case 10:
  90. return GPIO_PIN_10;
  91. case 11:
  92. return GPIO_PIN_11;
  93. case 12:
  94. return GPIO_PIN_12;
  95. case 13:
  96. return GPIO_PIN_13;
  97. case 14:
  98. return GPIO_PIN_14;
  99. case 15:
  100. return GPIO_PIN_15;
  101. default:
  102. break;
  103. };
  104. return 0;
  105. }