flipper_hal.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Flipper devices inc.
  3. GPIO and HAL implementations
  4. */
  5. #pragma once
  6. #include <stdio.h>
  7. #include <stdbool.h>
  8. #include "main.h"
  9. typedef enum {
  10. GpioModeInput,
  11. GpioModeOutput,
  12. GpioModeOpenDrain
  13. } GpioMode;
  14. typedef struct {
  15. const char* port;
  16. uint32_t pin;
  17. GpioMode mode;
  18. } GpioPin;
  19. void app_gpio_init(GpioPin gpio, GpioMode mode);
  20. inline void app_gpio_write(GpioPin gpio, bool state) {
  21. if(gpio.pin != 0) {
  22. if(state) {
  23. printf("[GPIO] %s%d on\n", gpio.port, gpio.pin);
  24. } else {
  25. printf("[GPIO] %s%d off\n", gpio.port, gpio.pin);
  26. }
  27. } else {
  28. printf("[GPIO] no pin\n");
  29. }
  30. }
  31. inline bool app_gpio_read(GpioPin gpio) {
  32. // TODO emulate pin state?
  33. return false;
  34. }
  35. typedef enum {
  36. GPIO_PIN_SET = 1,
  37. GPIO_PIN_RESET = 0
  38. } HAL_GPIO_PIN_STATE;
  39. void HAL_GPIO_WritePin(const char* port, uint32_t pin, HAL_GPIO_PIN_STATE state);
  40. void delay_us(uint32_t time);
  41. void pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel);
  42. extern TIM_HandleTypeDef htim8;
  43. inline void app_tim_ic_init(bool both) {
  44. printf("[TIM] init\n");
  45. }
  46. inline void app_tim_pulse(uint32_t width) {
  47. printf("[TIM] pulse %d\n", width);
  48. }
  49. inline void app_tim_stop() {
  50. printf("[TIM] stop\n");
  51. }
  52. #define GPIOA "PA"
  53. #define GPIOB "PB"
  54. #define GPIOC "PC"
  55. #define GPIOD "PD"
  56. #define GPIOE "PE"
  57. #define GPIO_PIN_0 0
  58. #define GPIO_PIN_1 1
  59. #define GPIO_PIN_2 2
  60. #define GPIO_PIN_3 3
  61. #define GPIO_PIN_4 4
  62. #define GPIO_PIN_5 5
  63. #define GPIO_PIN_6 6
  64. #define GPIO_PIN_7 7
  65. #define GPIO_PIN_8 8
  66. #define GPIO_PIN_9 9
  67. #define GPIO_PIN_10 10
  68. #define GPIO_PIN_11 11
  69. #define GPIO_PIN_12 12
  70. #define GPIO_PIN_13 13
  71. #define GPIO_PIN_14 14
  72. #define GPIO_PIN_15 15
  73. #define DISPLAY_RST_GPIO_Port "DISPLAY RST"
  74. #define DISPLAY_DI_Pin 0
  75. #define DISPLAY_DI_GPIO_Port "DISPLAY DI"
  76. #define DISPLAY_RST_Pin 0
  77. #define DISPLAY_CS_GPIO_Port "DISPLAY CS"
  78. #define DISPLAY_CS_Pin 0
  79. #define DISPLAY_BACKLIGHT_GPIO_Port "BACKLIGHT"
  80. #define DISPLAY_BACKLIGHT_Pin 0
  81. typedef const char* SPI_HandleTypeDef;
  82. typedef uint32_t HAL_StatusTypeDef;
  83. HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);