From 97e8de0bc9bc22f92e8c8d6cf70403925f14957a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 4 May 2017 12:06:42 +0200 Subject: [PATCH] fix tm1637: always send 3 command types --- lib/led_tm1637.c | 100 ++++++++++++++++++++++------------------------- lib/led_tm1637.h | 11 ++---- 2 files changed, 49 insertions(+), 62 deletions(-) diff --git a/lib/led_tm1637.c b/lib/led_tm1637.c index 2d11b11..8cec959 100644 --- a/lib/led_tm1637.c +++ b/lib/led_tm1637.c @@ -12,13 +12,14 @@ * along with this program. If not, see . * */ -/** library to communicate with a Titan Micro TM1637 IC attached to a 4-digit 7-segment (code) +/** library to communicate with a Titan Micro TM1637 IC attached to a 7-segment displays (code) * @file led_tm1637.c * @author King Kévin * @date 2017 * @note peripherals used: GPIO @ref led_tm1637_gpio, timer @ref led_tm1637_timer - * @note the protocol is very similar to I2C but incompatible for the following reasons: the capacitance is too large for open-drain type output with weak pull-up resistors (push-pull needs to be used, preventing to get ACKs since no indication of the ACK timing is provided); the devices doesn't use addresses; the STM32 I2C will switch to receiver mode when the first sent byte (the I2C address) has last bit set to 1 (such as for address commands with B7=1 where B7 is transmitted last), preventing to send further bytes (the data byte after the address) + * @note only 4-digit 7-segment displays are considered as this is the most common case * @warning all calls are blocking + * @note the protocol is very similar to I2C but incompatible for the following reasons: the pin capacitance is too large for open-drain type output with weak pull-up resistors (push-pull needs to be used, preventing to get ACKs since no indication of the ACK timing is provided); the devices doesn't use addresses; the STM32 I2C will switch to receiver mode when the first sent byte (the I2C address) has last bit set to 1 (such as for address commands with B7=1 where B7 is transmitted last), preventing to send further bytes (the data byte after the address) * * bit vs segment: 0bpgfedcba * +a+ @@ -30,7 +31,7 @@ /* standard libraries */ #include // standard integer types -#include // general utilities +#include // memory utilities #include // string utilities /* STM32 (including CM3) libraries */ @@ -58,9 +59,7 @@ /** @} */ /** display brightness */ -static enum led_tm1637_brightness_t display_brightness = LED_TM1637_14DIV16; -/** if display is on */ -static bool display_on = false; +enum led_tm1637_brightness_t display_brightness = LED_TM1637_14DIV16; /** ASCII characters encoded for the 7 segments digit block * @note starts with space @@ -198,14 +197,15 @@ static inline void led_tm1637_tick(void) * @return if write succeeded * @note includes start and stop conditions */ -static bool led_tm1637_write(const uint8_t* data, size_t length) +static bool led_tm1637_write(const uint8_t* data, uint8_t length) { bool to_return = true; // return if write succeeded - if (data==NULL || length==0) { // verify there it data to be read + if (NULL==data || 0==length) { // verify there it data to be read return false; } // enable timer for signal generation + gpio_set_mode(GPIO(LED_TM1637_DIO_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_TM1637_DIO_PIN)); // ensure we can output to sent start condition timer_set_counter(TIM(LED_TM1637_TIMER), 0); // reset timer counter timer_enable_counter(TIM(LED_TM1637_TIMER)); // enable timer to generate timing led_tm1637_tick(); // wait to enforce minimum time since last write @@ -216,8 +216,9 @@ static bool led_tm1637_write(const uint8_t* data, size_t length) gpio_clear(GPIO(LED_TM1637_CLK_PORT), GPIO(LED_TM1637_CLK_PIN)); // put CLK low // send data bytes (MSb first) - for (size_t i=0; i. * */ -/** library to communicate with a Titan Micro TM1637 IC attached to a 4-digit 7-segment (API) +/** library to communicate with a Titan Micro TM1637 IC attached to a 7-segment displays (API) * @file led_tm1637.h * @author King Kévin * @date 2017 * @note peripherals used: GPIO @ref led_tm1637_gpio, timer @ref led_tm1637_timer + * @note only 4-digit 7-segment displays are considered as this is the most common case * @warning all calls are blocking */ #pragma once @@ -40,16 +41,11 @@ void led_tm1637_setup(void); /** switch display on * @return if transmission succeeded */ -bool led_tm1637_on(void); -/** switch display off - * @return if transmission succeeded - */ bool led_tm1637_off(void); /** set display brightness * @param[in] brightness brightness level to set - * @return if transmission succeeded */ -bool led_tm1637_brightness(enum led_tm1637_brightness_t brightness); +void led_tm1637_brightness(enum led_tm1637_brightness_t brightness); /** display number * @param[in] number number to display (0-9999) * @return if transmission succeeded @@ -68,4 +64,3 @@ bool led_tm1637_time(uint8_t hours, uint8_t minutes); * @return if transmission succeeded */ bool led_tm1637_text(char* text); -