LibDriver TM1638  1.0.0
TM1638 full-featured driver
driver_tm1638_read_test.c
Go to the documentation of this file.
1 
38 #include <stdlib.h>
39 
40 static tm1638_handle_t gs_handle;
50 uint8_t tm1638_read_test(uint32_t times)
51 {
52  uint8_t res;
53  uint32_t i;
54  tm1638_info_t info;
55 
56  /* link interface function */
64 
65  /* get information */
66  res = tm1638_info(&info);
67  if (res != 0)
68  {
69  tm1638_interface_debug_print("tm1638: get info failed.\n");
70 
71  return 1;
72  }
73  else
74  {
75  /* print chip info */
76  tm1638_interface_debug_print("tm1638: chip is %s.\n", info.chip_name);
77  tm1638_interface_debug_print("tm1638: manufacturer is %s.\n", info.manufacturer_name);
78  tm1638_interface_debug_print("tm1638: interface is %s.\n", info.interface);
79  tm1638_interface_debug_print("tm1638: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80  tm1638_interface_debug_print("tm1638: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81  tm1638_interface_debug_print("tm1638: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82  tm1638_interface_debug_print("tm1638: max current is %0.2fmA.\n", info.max_current_ma);
83  tm1638_interface_debug_print("tm1638: max temperature is %0.1fC.\n", info.temperature_max);
84  tm1638_interface_debug_print("tm1638: min temperature is %0.1fC.\n", info.temperature_min);
85  }
86 
87  /* start read test */
88  tm1638_interface_debug_print("tm1638: start read test.\n");
89 
90  /* tm1638 init */
91  res = tm1638_init(&gs_handle);
92  if (res != 0)
93  {
94  tm1638_interface_debug_print("tm1638: init failed.\n");
95 
96  return 1;
97  }
98 
99  for (i = 0; i < times; i++)
100  {
101  uint8_t segk[4];
102 
103  /* delay 3000ms */
105 
106  /* read segment */
107  res = tm1638_read_segment(&gs_handle, segk);
108  if (res != 0)
109  {
110  tm1638_interface_debug_print("tm1638: read segment failed.\n");
111  (void)tm1638_deinit(&gs_handle);
112 
113  return 1;
114  }
115 
116  /* output */
117  tm1638_interface_debug_print("tm1638: segk[0]: 0x%02X.\n", segk[0]);
118  tm1638_interface_debug_print("tm1638: segk[1]: 0x%02X.\n", segk[1]);
119  tm1638_interface_debug_print("tm1638: segk[2]: 0x%02X.\n", segk[2]);
120  tm1638_interface_debug_print("tm1638: segk[3]: 0x%02X.\n", segk[3]);
121  }
122 
123  /* finish read test */
124  tm1638_interface_debug_print("tm1638: finish read test.\n");
125  (void)tm1638_deinit(&gs_handle);
126 
127  return 0;
128 }
driver tm1638 read test header file
uint8_t tm1638_deinit(tm1638_handle_t *handle)
close the chip
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_info(tm1638_info_t *info)
get chip's information
uint8_t tm1638_interface_spi_read(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi read
void tm1638_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1638_interface_spi_deinit(void)
interface spi deinit
uint8_t tm1638_interface_spi_init(void)
interface spi init
uint8_t tm1638_interface_spi_write(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi write
void tm1638_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tm1638_read_test(uint32_t times)
read test
tm1638 handle structure definition
tm1638 information structure definition
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]