LibDriver TM1638
Loading...
Searching...
No Matches
driver_tm1638.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_TM1638_H
38#define DRIVER_TM1638_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
67
71typedef enum
72{
76
91
108
112typedef struct tm1638_handle_s
113{
114 uint8_t (*spi_init)(void);
115 uint8_t (*spi_deinit)(void);
116 uint8_t (*spi_write)(uint8_t addr, uint8_t *buf, uint16_t len);
117 uint8_t (*spi_read)(uint8_t addr, uint8_t *buf, uint16_t len);
118 void (*delay_ms)(uint32_t ms);
119 void (*debug_print)(const char *const fmt, ...);
120 uint8_t inited;
121 uint8_t display_conf;
122 uint8_t data_conf;
124
140
144
151
158#define DRIVER_TM1638_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
159
166#define DRIVER_TM1638_LINK_SPI_INIT(HANDLE, FUC) (HANDLE)->spi_init = FUC
167
174#define DRIVER_TM1638_LINK_SPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_deinit = FUC
175
182#define DRIVER_TM1638_LINK_SPI_WRITE(HANDLE, FUC) (HANDLE)->spi_write = FUC
183
190#define DRIVER_TM1638_LINK_SPI_READ(HANDLE, FUC) (HANDLE)->spi_read = FUC
191
198#define DRIVER_TM1638_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
199
206#define DRIVER_TM1638_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
207
211
218
227uint8_t tm1638_info(tm1638_info_t *info);
228
239uint8_t tm1638_init(tm1638_handle_t *handle);
240
252
264uint8_t tm1638_deinit(tm1638_handle_t *handle);
265
280uint8_t tm1638_write_segment(tm1638_handle_t *handle, uint8_t addr, uint16_t *data, uint8_t len);
281
293uint8_t tm1638_read_segment(tm1638_handle_t *handle, uint8_t segk[4]);
294
307
319
331uint8_t tm1638_set_display(tm1638_handle_t *handle, tm1638_bool_t enable);
332
343uint8_t tm1638_get_display(tm1638_handle_t *handle, tm1638_bool_t *enable);
344
357
369
381uint8_t tm1638_set_test_mode(tm1638_handle_t *handle, tm1638_bool_t enable);
382
393uint8_t tm1638_get_test_mode(tm1638_handle_t *handle, tm1638_bool_t *enable);
394
398
405
419uint8_t tm1638_set_reg(tm1638_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len);
420
434uint8_t tm1638_get_reg(tm1638_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len);
435
439
443
444#ifdef __cplusplus
445}
446#endif
447
448#endif
uint8_t tm1638_get_test_mode(tm1638_handle_t *handle, tm1638_bool_t *enable)
get test mode status
uint8_t tm1638_write_segment(tm1638_handle_t *handle, uint8_t addr, uint16_t *data, uint8_t len)
write segment
tm1638_bool_t
tm1638 bool enumeration definition
struct tm1638_handle_s tm1638_handle_t
tm1638 handle structure definition
uint8_t tm1638_set_address_mode(tm1638_handle_t *handle, tm1638_address_mode_t mode)
set address mode
tm1638_address_mode_t
tm1638 address mode enumeration definition
uint8_t tm1638_set_pulse_width(tm1638_handle_t *handle, tm1638_pulse_width_t width)
set pulse width
tm1638_number_t
tm1638 number enumeration definition
uint8_t tm1638_deinit(tm1638_handle_t *handle)
close the chip
uint8_t tm1638_clear_segment(tm1638_handle_t *handle)
clear segment
uint8_t tm1638_init(tm1638_handle_t *handle)
initialize the chip
uint8_t tm1638_read_segment(tm1638_handle_t *handle, uint8_t segk[4])
read segment
uint8_t tm1638_set_display(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable display
tm1638_pulse_width_t
tm1638 pulse width enumeration definition
uint8_t tm1638_get_display(tm1638_handle_t *handle, tm1638_bool_t *enable)
get display status
uint8_t tm1638_get_address_mode(tm1638_handle_t *handle, tm1638_address_mode_t *mode)
get address mode
uint8_t tm1638_set_test_mode(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable test mode
struct tm1638_info_s tm1638_info_t
tm1638 information structure definition
uint8_t tm1638_info(tm1638_info_t *info)
get chip's information
uint8_t tm1638_get_pulse_width(tm1638_handle_t *handle, tm1638_pulse_width_t *width)
get pulse width
@ TM1638_BOOL_FALSE
@ TM1638_BOOL_TRUE
@ TM1638_ADDRESS_MODE_FIX
@ TM1638_ADDRESS_MODE_INC
@ TM1638_NUMBER_4
@ TM1638_NUMBER_2
@ TM1638_NUMBER_9
@ TM1638_NUMBER_3
@ TM1638_NUMBER_8
@ TM1638_NUMBER_5
@ TM1638_NUMBER_7
@ TM1638_NUMBER_6
@ TM1638_NUMBER_0
@ TM1638_NUMBER_1
@ TM1638_PULSE_WIDTH_14_DIV_16
@ TM1638_PULSE_WIDTH_12_DIV_16
@ TM1638_PULSE_WIDTH_1_DIV_16
@ TM1638_PULSE_WIDTH_4_DIV_16
@ TM1638_PULSE_WIDTH_13_DIV_16
@ TM1638_PULSE_WIDTH_2_DIV_16
@ TM1638_PULSE_WIDTH_11_DIV_16
@ TM1638_PULSE_WIDTH_10_DIV_16
uint8_t tm1638_set_reg(tm1638_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len)
set the chip register
uint8_t tm1638_get_reg(tm1638_handle_t *handle, uint8_t cmd, uint8_t *data, uint8_t len)
get the chip register
tm1638 handle structure definition
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
uint8_t(* spi_write)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* spi_read)(uint8_t addr, uint8_t *buf, uint16_t len)
tm1638 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]