医美代码重构
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.

81 lines
2.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "port.h"
  2. #include "driver/gpio.h"
  3. #include "esp_log.h"
  4. uint32_t port_get_ticket() { return esp_log_timestamp(); }
  5. uint32_t port_haspassedms(uint32_t ticket) { return port_get_ticket() - ticket; }
  6. uint32_t port_delay_ms(uint32_t ms) {
  7. uint32_t now = port_get_ticket();
  8. while (port_get_ticket() - now < ms) {
  9. }
  10. return 0;
  11. }
  12. void gpio_electric_relay_init() {
  13. { // ELECTRIC_RELAY1
  14. gpio_config_t gpio_grb_led_structer;
  15. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  16. gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
  17. gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_ELECTRIC_RELAY1);
  18. gpio_grb_led_structer.pull_down_en = 0;
  19. gpio_grb_led_structer.pull_up_en = 0;
  20. gpio_config(&gpio_grb_led_structer);
  21. }
  22. { // ELECTRIC_RELAY2
  23. gpio_config_t gpio_grb_led_structer;
  24. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  25. gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
  26. gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_ELECTRIC_RELAY2);
  27. gpio_grb_led_structer.pull_down_en = 0;
  28. gpio_grb_led_structer.pull_up_en = 0;
  29. gpio_config(&gpio_grb_led_structer);
  30. }
  31. }
  32. void gpio_output_debug_light_init() {
  33. gpio_config_t gpio_grb_led_structer;
  34. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  35. gpio_grb_led_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  36. gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_DEBUG_LIGHT);
  37. gpio_grb_led_structer.pull_down_en = 0;
  38. gpio_grb_led_structer.pull_up_en = 0;
  39. gpio_config(&gpio_grb_led_structer);
  40. }
  41. void port_do_debug_light_state(uint16_t interval_time) {
  42. static uint32_t debug_light_time;
  43. if (port_haspassedms(debug_light_time) > interval_time) {
  44. gpio_set_level(GPIO_DEBUG_LIGHT, !gpio_get_level(GPIO_DEBUG_LIGHT));
  45. debug_light_time = port_get_ticket();
  46. }
  47. }
  48. void gpio_input_key_init() {
  49. { // Key1
  50. gpio_config_t gpio_grb_led_structer;
  51. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  52. gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
  53. gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_KEY_INT1);
  54. gpio_grb_led_structer.pull_down_en = 0;
  55. gpio_grb_led_structer.pull_up_en = 0;
  56. gpio_config(&gpio_grb_led_structer);
  57. }
  58. { // Key2
  59. gpio_config_t gpio_grb_led_structer;
  60. gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
  61. gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
  62. gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_KEY_INT2);
  63. gpio_grb_led_structer.pull_down_en = 0;
  64. gpio_grb_led_structer.pull_up_en = 0;
  65. gpio_config(&gpio_grb_led_structer);
  66. }
  67. }