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.

71 lines
1.1 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
  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) { return (pin & 0xF); }