From 818e16e79331b1457713991e78174754a1bd03ef Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Wed, 5 Mar 2025 18:56:43 +0800 Subject: [PATCH] blink LED on epd busy --- EPD/EPD_driver.c | 27 +++++++++++++++++++++++++++ EPD/EPD_driver.h | 5 +++++ EPD/EPD_service.c | 38 ++++++++++++-------------------------- EPD/UC8176.c | 2 +- html/index.html | 1 + 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/EPD/EPD_driver.c b/EPD/EPD_driver.c index f78c69a..74c653e 100644 --- a/EPD/EPD_driver.c +++ b/EPD/EPD_driver.c @@ -29,6 +29,7 @@ uint32_t EPD_RST_PIN = 11; uint32_t EPD_BUSY_PIN = 12; uint32_t EPD_BS_PIN = 13; uint32_t EPD_EN_PIN = 0xFF; +uint32_t EPD_LED_PIN = 0xFF; #define SPI_INSTANCE 0 /**< SPI instance index. */ static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */ @@ -110,6 +111,11 @@ void DEV_Module_Init(void) digitalWrite(EPD_DC_PIN, LOW); digitalWrite(EPD_CS_PIN, LOW); digitalWrite(EPD_RST_PIN, HIGH); + + if (EPD_LED_PIN != 0xFF) { + pinMode(EPD_LED_PIN, OUTPUT); + EPD_LED_ON(); + } } void DEV_Module_Exit(void) @@ -119,6 +125,8 @@ void DEV_Module_Exit(void) digitalWrite(EPD_RST_PIN, LOW); nrf_drv_spi_uninit(&spi); + + EPD_LED_OFF(); } void DEV_SPI_WriteByte(uint8_t value) @@ -164,6 +172,7 @@ void EPD_WaitBusy(uint32_t value, uint16_t timeout) { NRF_LOG_DEBUG("[EPD]: check busy"); while (digitalRead(EPD_BUSY_PIN) == value) { + if (timeout % 100 == 0) EPD_LED_TOGGLE(); delay(1); timeout--; if (timeout == 0) { @@ -174,6 +183,24 @@ void EPD_WaitBusy(uint32_t value, uint16_t timeout) NRF_LOG_DEBUG("[EPD]: busy release"); } +void EPD_LED_ON(void) +{ + if (EPD_LED_PIN != 0xFF) + digitalWrite(EPD_LED_PIN, LOW); +} + +void EPD_LED_OFF(void) +{ + if (EPD_LED_PIN != 0xFF) + digitalWrite(EPD_LED_PIN, HIGH); +} + +void EPD_LED_TOGGLE(void) +{ + if (EPD_LED_PIN != 0xFF) + nrf_gpio_pin_toggle(EPD_LED_PIN); +} + extern epd_driver_t epd_driver_4in2; extern epd_driver_t epd_driver_4in2bv2; diff --git a/EPD/EPD_driver.h b/EPD/EPD_driver.h index 1f2ae80..efda620 100644 --- a/EPD/EPD_driver.h +++ b/EPD/EPD_driver.h @@ -53,6 +53,7 @@ extern uint32_t EPD_RST_PIN; extern uint32_t EPD_BUSY_PIN; extern uint32_t EPD_BS_PIN; extern uint32_t EPD_EN_PIN; +extern uint32_t EPD_LED_PIN; #define LOW (0x0) #define HIGH (0x1) @@ -80,6 +81,10 @@ void EPD_WriteData(uint8_t *Data, uint8_t Len); void EPD_Reset(uint32_t value, uint16_t duration); void EPD_WaitBusy(uint32_t value, uint16_t timeout); +void EPD_LED_ON(void); +void EPD_LED_OFF(void); +void EPD_LED_TOGGLE(void); + epd_driver_t *epd_driver_get(void); epd_driver_t *epd_driver_by_id(uint8_t id); bool epd_driver_set(uint8_t id); diff --git a/EPD/EPD_service.c b/EPD/EPD_service.c index 5e3f04f..a1506fc 100644 --- a/EPD/EPD_service.c +++ b/EPD/EPD_service.c @@ -35,18 +35,6 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define EPD_CONFIG_SIZE (sizeof(epd_config_t) / sizeof(uint8_t)) -static void led_on(ble_epd_t * p_epd) -{ - if (p_epd->config.led_pin == 0xFF) return; - nrf_gpio_pin_clear(p_epd->config.led_pin); -} - -static void led_off(ble_epd_t * p_epd) -{ - if (p_epd->config.led_pin == 0xFF) return; - nrf_gpio_pin_set(p_epd->config.led_pin); -} - /**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice. * * @param[in] p_epd EPD Service structure. @@ -54,7 +42,6 @@ static void led_off(ble_epd_t * p_epd) */ static void on_connect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt) { - led_on(p_epd); p_epd->conn_handle = p_ble_evt->evt.gap_evt.conn_handle; } @@ -67,7 +54,6 @@ static void on_connect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt) static void on_disconnect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt) { UNUSED_PARAMETER(p_ble_evt); - led_off(p_epd); p_epd->conn_handle = BLE_CONN_HANDLE_INVALID; } @@ -163,7 +149,6 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le static void on_write(ble_epd_t * p_epd, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; - uint32_t err_code; if ( (p_evt_write->handle == p_epd->char_handles.cccd_handle) @@ -177,7 +162,7 @@ static void on_write(ble_epd_t * p_epd, ble_evt_t * p_ble_evt) p_epd->is_notification_enabled = true; static uint16_t length = sizeof(epd_config_t); NRF_LOG_DEBUG("send epd config\n"); - err_code = ble_epd_string_send(p_epd, (uint8_t *)&p_epd->config, length); + uint32_t err_code = ble_epd_string_send(p_epd, (uint8_t *)&p_epd->config, length); if (err_code != NRF_ERROR_INVALID_STATE) APP_ERROR_CHECK(err_code); } @@ -294,15 +279,25 @@ static void ble_epd_config_load(ble_epd_t * p_epd) EPD_BUSY_PIN = p_epd->config.busy_pin; EPD_BS_PIN = p_epd->config.bs_pin; EPD_EN_PIN = p_epd->config.en_pin; + EPD_LED_PIN = p_epd->config.led_pin; epd_driver_set(p_epd->config.driver_id); p_epd->driver = epd_driver_get(); + + // blink LED on start + if (EPD_LED_PIN != 0xFF) + { + pinMode(EPD_LED_PIN, OUTPUT); + EPD_LED_ON(); + delay(100); + EPD_LED_OFF(); + } } void ble_epd_sleep_prepare(ble_epd_t * p_epd) { // Turn off led - led_off(p_epd); + EPD_LED_OFF(); // Prepare wakeup pin if (p_epd->config.wakeup_pin != 0xFF) { @@ -324,15 +319,6 @@ uint32_t ble_epd_init(ble_epd_t * p_epd, epd_callback_t cmd_cb) epd_config_load(&p_epd->config); ble_epd_config_load(p_epd); - // Init led pin - if (p_epd->config.led_pin != 0xFF) - { - nrf_gpio_cfg_output(p_epd->config.led_pin); - led_on(p_epd); - nrf_delay_ms(50); - led_off(p_epd); - } - // Add the service. return epd_service_init(p_epd); } diff --git a/EPD/UC8176.c b/EPD/UC8176.c index 51b8034..bc10ec9 100644 --- a/EPD/UC8176.c +++ b/EPD/UC8176.c @@ -55,7 +55,7 @@ void EPD_4IN2_Refresh(void) EPD_4IN2_PowerOn(); EPD_WriteCommand(0x12); delay(100); - EPD_WaitBusy(LOW, 50); + EPD_WaitBusy(LOW, 20000); EPD_4IN2_PowerOff(); } diff --git a/html/index.html b/html/index.html index f083d6b..880ec7a 100644 --- a/html/index.html +++ b/html/index.html @@ -108,6 +108,7 @@
提示 +

驱动板上 LED 灯(如果有的话)闪烁的时候表示墨水屏处于忙碌状态,此时上位机发送的指令可能会不会被执行