flipper_hal.h 2.1 KB

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