42#define CHIP_NAME "Titan Micro Electronics TM1637"
43#define MANUFACTURER_NAME "Titan Micro Electronics"
44#define SUPPLY_VOLTAGE_MIN 3.3f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 200.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define TM1637_COMMAND_DATA (1 << 6)
55#define TM1637_COMMAND_DISPLAY (2 << 6)
56#define TM1637_COMMAND_ADDRESS (3 << 6)
64static uint8_t a_high_low_shift(uint8_t data)
68 output = (data << 4) | (data >> 4);
69 output = ((output << 2) & 0xCC) | ((output >> 2) & 0x33);
70 output = ((output << 1) & 0xAA) | ((output >> 1) & 0x55);
86static uint8_t a_tm1637_write(
tm1637_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
88 uint8_t inner_buffer[16];
95 for (i = 0; i < len; i++)
97 inner_buffer[i] = a_high_low_shift(buf[i]);
118static uint8_t a_tm1637_read(
tm1637_handle_t *handle, uint8_t cmd, uint8_t *buf, uint16_t len)
126 for (i = 0; i < len; i++)
128 buf[i] = a_high_low_shift(buf[i]);
156 handle->
debug_print(
"tm1637: iic_init is null.\n");
162 handle->
debug_print(
"tm1637: iic_deinit is null.\n");
168 handle->
debug_print(
"tm1637: iic_write_cmd_custom is null.\n");
174 handle->
debug_print(
"tm1637: iic_read_cmd_custom is null.\n");
180 handle->
debug_print(
"tm1637: delay_ms is null.\n");
225 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
227 handle->
debug_print(
"tm1637: power down failed.\n");
235 handle->
debug_print(
"tm1637: iic deinit failed.\n");
271 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
334 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
397 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
460 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
531 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
539 for (i = 0; i < len; i++)
542 if (a_tm1637_write(handle, cmd, &data[i], 1) != 0)
553 if (a_tm1637_write(handle, cmd, data, len) != 0)
578 uint8_t data[6] = {0};
590 if (a_tm1637_write(handle, cmd, NULL, 0) != 0)
598 for (i = 0; i < 6; i++)
601 if (a_tm1637_write(handle, cmd, data + i, 1) != 0)
612 if (a_tm1637_write(handle, cmd, data, 6) != 0)
650 if (a_tm1637_read(handle, cmd, &data, 1) != 0)
657 *k = (data >> 3) & 0x03;
686 if (a_tm1637_write(handle, cmd, data, len) != 0)
720 if (a_tm1637_read(handle, cmd, data, len) != 0)
#define TM1637_COMMAND_DATA
chip command definition
#define TM1637_COMMAND_DISPLAY
#define SUPPLY_VOLTAGE_MAX
#define TM1637_COMMAND_ADDRESS
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
driver tm1637 header file
uint8_t tm1637_read_segment(tm1637_handle_t *handle, uint8_t *seg, uint8_t *k)
read segment
uint8_t tm1637_set_address_mode(tm1637_handle_t *handle, tm1637_address_mode_t mode)
set address mode
uint8_t tm1637_info(tm1637_info_t *info)
get chip's information
uint8_t tm1637_deinit(tm1637_handle_t *handle)
close the chip
tm1637_address_mode_t
tm1637 address mode enumeration definition
tm1637_pulse_width_t
tm1637 pulse width enumeration definition
uint8_t tm1637_get_display(tm1637_handle_t *handle, tm1637_bool_t *enable)
get display status
tm1637_bool_t
tm1637 bool enumeration definition
uint8_t tm1637_clear_segment(tm1637_handle_t *handle)
clear segment
uint8_t tm1637_get_test_mode(tm1637_handle_t *handle, tm1637_bool_t *enable)
get test mode status
uint8_t tm1637_get_pulse_width(tm1637_handle_t *handle, tm1637_pulse_width_t *width)
get pulse width
struct tm1637_info_s tm1637_info_t
tm1637 information structure definition
uint8_t tm1637_set_test_mode(tm1637_handle_t *handle, tm1637_bool_t enable)
enable or disable test mode
struct tm1637_handle_s tm1637_handle_t
tm1637 handle structure definition
uint8_t tm1637_write_segment(tm1637_handle_t *handle, uint8_t addr, uint8_t *data, uint8_t len)
write segment
uint8_t tm1637_get_address_mode(tm1637_handle_t *handle, tm1637_address_mode_t *mode)
get address mode
uint8_t tm1637_set_pulse_width(tm1637_handle_t *handle, tm1637_pulse_width_t width)
set pulse width
uint8_t tm1637_set_display(tm1637_handle_t *handle, tm1637_bool_t enable)
enable or disable display
uint8_t tm1637_init(tm1637_handle_t *handle)
initialize the chip
uint8_t tm1637_get_reg(tm1637_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len)
get the chip register
uint8_t tm1637_set_reg(tm1637_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len)
set the chip register
uint8_t(* iic_write_cmd_custom)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_read_cmd_custom)(uint8_t addr, uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v