42#define CHIP_NAME                 "NXP PCF8563"         
   43#define MANUFACTURER_NAME         "NXP"                 
   44#define SUPPLY_VOLTAGE_MIN        1.9f                  
   45#define SUPPLY_VOLTAGE_MAX        5.5f                  
   46#define MAX_CURRENT               0.80f                 
   47#define TEMPERATURE_MIN           -40.0f                
   48#define TEMPERATURE_MAX           85.0f                 
   49#define DRIVER_VERSION            1000                  
   54#define PCF8563_REG_CONTROL_STATUS1      0x00         
   55#define PCF8563_REG_CONTROL_STATUS2      0x01         
   56#define PCF8563_REG_SECOND               0x02         
   57#define PCF8563_REG_MINUTE               0x03         
   58#define PCF8563_REG_HOUR                 0x04         
   59#define PCF8563_REG_DAY                  0x05         
   60#define PCF8563_REG_WEEK                 0x06         
   61#define PCF8563_REG_MONTH                0x07         
   62#define PCF8563_REG_YEAR                 0x08         
   63#define PCF8563_REG_MINUTE_ALARM         0x09         
   64#define PCF8563_REG_HOUR_ALARM           0x0A         
   65#define PCF8563_REG_DAY_ALARM            0x0B         
   66#define PCF8563_REG_WEEK_ALARM           0x0C         
   67#define PCF8563_REG_CLKOUT_CONTROL       0x0D         
   68#define PCF8563_REG_TIMER_CONTROL        0x0E         
   69#define PCF8563_REG_TIMER                0x0F         
   74#define PCF8563_ADDRESS        0xA2          
   86static uint8_t a_pcf8563_iic_write(
pcf8563_handle_t *handle, uint8_t reg, uint8_t data)
 
  107static uint8_t a_pcf8563_iic_multiple_read(
pcf8563_handle_t *handle, uint8_t reg, uint8_t *buf, uint8_t len)
 
  123static uint8_t a_pcf8563_hex2bcd(uint8_t val)
 
  140static uint8_t a_pcf8563_bcd2hex(uint8_t val)
 
  145    val = (val >> 4) & 0x0F;        
 
  184    if ((t->
year < 2000) || (t->
year > 2199))                                                                
 
  186        handle->
debug_print(
"pcf8563: year can't be over 2199 or less than 2000.\n");                        
 
  192        handle->
debug_print(
"pcf8563: month can't be zero or over than 12.\n");                              
 
  198        handle->
debug_print(
"pcf8563: week can't be over than 6.\n");                                        
 
  202    if ((t->
date == 0) || (t->
date > 31))                                                                    
 
  204        handle->
debug_print(
"pcf8563: date can't be zero or over than 31.\n");                               
 
  210        handle->
debug_print(
"pcf8563: hour can't be over than 23.\n");                                       
 
  216        handle->
debug_print(
"pcf8563: minute can't be over than 59.\n");                                     
 
  222        handle->
debug_print(
"pcf8563: second can't be over than 59.\n");                                     
 
  229        handle->
debug_print(
"pcf8563: write second failed.\n");                                              
 
  236        handle->
debug_print(
"pcf8563: write minute failed.\n");                                              
 
  243        handle->
debug_print(
"pcf8563: write hour failed.\n");                                                
 
  250        handle->
debug_print(
"pcf8563: write week failed.\n");                                                
 
  257        handle->
debug_print(
"pcf8563: write day failed.\n");                                                 
 
  261    year = t->
year - 2000;                                                                                   
 
  267            handle->
debug_print(
"pcf8563: write century and month failed.\n");                               
 
  272        res = a_pcf8563_iic_write(handle, 
PCF8563_REG_YEAR, a_pcf8563_hex2bcd((uint8_t)year));               
 
  275            handle->
debug_print(
"pcf8563: write year failed.\n");                                            
 
  285            handle->
debug_print(
"pcf8563: write century and month failed.\n");                               
 
  289        res = a_pcf8563_iic_write(handle, 
PCF8563_REG_YEAR, a_pcf8563_hex2bcd((uint8_t)year));               
 
  292            handle->
debug_print(
"pcf8563: write year failed.\n");                                            
 
 
  333    memset(buf, 0, 
sizeof(uint8_t) * 7);                                                  
 
  337        handle->
debug_print(
"pcf8563: multiple read failed.\n");                          
 
  341    if (((buf[0] >> 7) & 0x01) != 0)                                                      
 
  343        handle->
debug_print(
"pcf8563: clock integrity is not guaranteed.\n");             
 
  347    t->
year = a_pcf8563_bcd2hex(buf[6]) + 2000;                                           
 
  348    if (((buf[5] >> 7) & 0x01) != 0)                                                      
 
  353    t->
month = a_pcf8563_bcd2hex(buf[5] & 0x1F);                                          
 
  354    t->
week = a_pcf8563_bcd2hex(buf[4] & 0x7);                                            
 
  355    t->
date = a_pcf8563_bcd2hex(buf[3] & 0x3F);                                           
 
  356    t->
hour = a_pcf8563_bcd2hex(buf[2] & 0x3F);                                           
 
  357    t->
minute = a_pcf8563_bcd2hex(buf[1] & 0x7F);                                         
 
  358    t->
second = a_pcf8563_bcd2hex(buf[0] & 0x7F);                                         
 
 
  391        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
  400        handle->
debug_print(
"pcf8563: write control status1 failed.\n");                     
 
 
  436        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
 
  473        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
  482        handle->
debug_print(
"pcf8563: write control status1 failed.\n");                     
 
 
  518        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
 
  555        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
  564        handle->
debug_print(
"pcf8563: write control status1 failed.\n");                     
 
 
  600        handle->
debug_print(
"pcf8563: read control status1 failed.\n");                      
 
 
  637        handle->
debug_print(
"pcf8563: read minute alarm failed.\n");                      
 
  642    prev |= (!enable) << 7;                                                               
 
  646        handle->
debug_print(
"pcf8563: write minute alarm failed.\n");                     
 
 
  682        handle->
debug_print(
"pcf8563: read minute alarm failed.\n");                      
 
 
  718        handle->
debug_print(
"pcf8563: minute can't be over than 59.\n");                  
 
  726        handle->
debug_print(
"pcf8563: read minute alarm failed.\n");                      
 
  730    prev &= ~(0x7F << 0);                                                                 
 
  731    prev |= a_pcf8563_hex2bcd(minute);                                                    
 
  735        handle->
debug_print(
"pcf8563: write minute alarm failed.\n");                     
 
 
  771        handle->
debug_print(
"pcf8563: read minute alarm failed.\n");                      
 
  775    *minute = a_pcf8563_bcd2hex(prev & 0x7F);                                             
 
 
  808        handle->
debug_print(
"pcf8563: read hour alarm failed.\n");                      
 
  813    prev |= (!enable) << 7;                                                             
 
  817        handle->
debug_print(
"pcf8563: write hour alarm failed.\n");                     
 
 
  853        handle->
debug_print(
"pcf8563: read hour alarm failed.\n");                      
 
 
  889        handle->
debug_print(
"pcf8563: hour can't be over than 23.\n");                  
 
  897        handle->
debug_print(
"pcf8563: read hour alarm failed.\n");                      
 
  901    prev &= ~(0x3F << 0);                                                               
 
  902    prev |= a_pcf8563_hex2bcd(hour);                                                    
 
  906        handle->
debug_print(
"pcf8563: write hour alarm failed.\n");                     
 
 
  942        handle->
debug_print(
"pcf8563: read hour alarm failed.\n");                      
 
  946    *hour = a_pcf8563_bcd2hex(prev & 0x3F);                                             
 
 
  979        handle->
debug_print(
"pcf8563: read day alarm failed.\n");                      
 
  984    prev |= (!enable) << 7;                                                            
 
  988        handle->
debug_print(
"pcf8563: write day alarm failed.\n");                     
 
 
 1024        handle->
debug_print(
"pcf8563: read day alarm failed.\n");                      
 
 
 1058    if ((day == 0) || (day > 31))                                                      
 
 1060        handle->
debug_print(
"pcf8563: day can't be zero or over than 31.\n");          
 
 1068        handle->
debug_print(
"pcf8563: read day alarm failed.\n");                      
 
 1072    prev &= ~(0x3F << 0);                                                              
 
 1073    prev |= a_pcf8563_hex2bcd(day);                                                    
 
 1077        handle->
debug_print(
"pcf8563: write day alarm failed.\n");                     
 
 
 1113        handle->
debug_print(
"pcf8563: read day alarm failed.\n");                      
 
 1117    *day = a_pcf8563_bcd2hex(prev & 0x3F);                                             
 
 
 1150        handle->
debug_print(
"pcf8563: read week alarm failed.\n");                     
 
 1155    prev |= (!enable) << 7;                                                            
 
 1159        handle->
debug_print(
"pcf8563: write week alarm failed.\n");                    
 
 
 1195        handle->
debug_print(
"pcf8563: read week alarm failed.\n");                     
 
 
 1231        handle->
debug_print(
"pcf8563: week can't be over than 6.\n");                   
 
 1239        handle->
debug_print(
"pcf8563: read week alarm failed.\n");                      
 
 1243    prev &= ~(0x7 << 0);                                                                
 
 1244    prev |= a_pcf8563_hex2bcd(week);                                                    
 
 1248        handle->
debug_print(
"pcf8563: write week alarm failed.\n");                     
 
 
 1284        handle->
debug_print(
"pcf8563: read week alarm failed.\n");                      
 
 1288    *week = a_pcf8563_bcd2hex(prev & 0x07);                                             
 
 
 1321        handle->
debug_print(
"pcf8563: read clkout control failed.\n");                     
 
 1326    prev |= enable << 7;                                                                   
 
 1330        handle->
debug_print(
"pcf8563: write clkout control failed.\n");                    
 
 
 1366        handle->
debug_print(
"pcf8563: read clkout control failed.\n");                     
 
 
 1403        handle->
debug_print(
"pcf8563: read clkout control failed.\n");                     
 
 1412        handle->
debug_print(
"pcf8563: write clkout control failed.\n");                    
 
 
 1448        handle->
debug_print(
"pcf8563: read clkout control failed.\n");                     
 
 
 1485        handle->
debug_print(
"pcf8563: read timer control failed.\n");                     
 
 1490    prev |= enable << 7;                                                                  
 
 1494        handle->
debug_print(
"pcf8563: write timer control failed.\n");                    
 
 
 1530        handle->
debug_print(
"pcf8563: read timer control failed.\n");                     
 
 
 1567        handle->
debug_print(
"pcf8563: read timer control failed.\n");                     
 
 1576        handle->
debug_print(
"pcf8563: write timer control failed.\n");                    
 
 
 1612        handle->
debug_print(
"pcf8563: read timer control failed.\n");                     
 
 
 1650        handle->
debug_print(
"pcf8563: write timer failed.\n");         
 
 
 1685        handle->
debug_print(
"pcf8563: read timer failed.\n");                     
 
 
 1721        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 1726    prev |= enable << 0;                                                                     
 
 1730        handle->
debug_print(
"pcf8563: write control status2 failed.\n");                     
 
 
 1766        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 
 1803        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 1808    prev |= enable << 1;                                                                     
 
 1812        handle->
debug_print(
"pcf8563: write control status2 failed.\n");                     
 
 
 1848        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 
 1885        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 1894        handle->
debug_print(
"pcf8563: write control status2 failed.\n");                     
 
 
 1930        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 
 1967        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 1973    if (((prev >> 2) & 0x1) != 0)                                                            
 
 1980    if (((prev >> 3) & 0x01) != 0)                                                           
 
 1990        handle->
debug_print(
"pcf8563: write control status2 failed.\n");                     
 
 
 2026        handle->
debug_print(
"pcf8563: read control status2 failed.\n");                      
 
 2041        handle->
debug_print(
"pcf8563: write control status2 failed.\n");                     
 
 
 2071        handle->
debug_print(
"pcf8563: iic_init is null.\n");         
 
 2077        handle->
debug_print(
"pcf8563: iic_deinit is null.\n");       
 
 2083        handle->
debug_print(
"pcf8563: iic_write is null.\n");        
 
 2089        handle->
debug_print(
"pcf8563: iic_read is null.\n");         
 
 2095        handle->
debug_print(
"pcf8563: delay_ms is null.\n");         
 
 2101        handle->
debug_print(
"pcf8563: receive_callback is null.\n"); 
 
 2108        handle->
debug_print(
"pcf8563: iic init failed.\n");          
 
 
 2140        handle->
debug_print(
"pcf8563: iic deinit failed.\n");       
 
 
#define PCF8563_REG_MINUTE_ALARM
#define PCF8563_REG_TIMER
#define PCF8563_REG_DAY_ALARM
#define PCF8563_ADDRESS
chip address definition
#define PCF8563_REG_CONTROL_STATUS2
#define SUPPLY_VOLTAGE_MAX
#define PCF8563_REG_MONTH
#define PCF8563_REG_MINUTE
#define PCF8563_REG_CONTROL_STATUS1
chip register definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define PCF8563_REG_SECOND
#define PCF8563_REG_HOUR_ALARM
#define PCF8563_REG_TIMER_CONTROL
#define CHIP_NAME
chip information definition
#define PCF8563_REG_CLKOUT_CONTROL
#define PCF8563_REG_WEEK_ALARM
driver pcf8563 header file
uint8_t pcf8563_info(pcf8563_info_t *info)
get chip's information
uint8_t pcf8563_set_week_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable week alarm
uint8_t pcf8563_set_hour_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable hour alarm
uint8_t pcf8563_set_timer_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable timer enable
pcf8563_timer_freq_t
pcf8563 timer freq enumeration definition
uint8_t pcf8563_set_day_alarm(pcf8563_handle_t *handle, uint8_t day)
set day alarm
uint8_t pcf8563_get_week_alarm(pcf8563_handle_t *handle, uint8_t *week)
get week alarm
uint8_t pcf8563_deinit(pcf8563_handle_t *handle)
close the chip
uint8_t pcf8563_get_minute_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the minute alarm status
pcf8563_bool_t
pcf8563 bool enumeration definition
uint8_t pcf8563_get_rtc_stop(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the rtc stop status
uint8_t pcf8563_set_clock_out(pcf8563_handle_t *handle, pcf8563_clock_out_t clk)
set clock out
uint8_t pcf8563_set_hour_alarm(pcf8563_handle_t *handle, uint8_t hour)
set hour alarm
uint8_t pcf8563_get_interrupt_mode(pcf8563_handle_t *handle, pcf8563_interrupt_mode_t *mode)
get the interrupt mode
uint8_t pcf8563_get_hour_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the hour alarm status
uint8_t pcf8563_get_alarm_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get alarm interrupt status
uint8_t pcf8563_get_timer_freq(pcf8563_handle_t *handle, pcf8563_timer_freq_t *freq)
get timer freq
uint8_t pcf8563_set_timer_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable timer interrupt
uint8_t pcf8563_set_test_mode(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable test mode
uint8_t pcf8563_set_minute_alarm(pcf8563_handle_t *handle, uint8_t minute)
set minute alarm
uint8_t pcf8563_set_timer_freq(pcf8563_handle_t *handle, pcf8563_timer_freq_t freq)
set timer freq
uint8_t pcf8563_set_clock_out_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable clock out enable
pcf8563_interrupt_mode_t
pcf8563 interrupt mode enumeration definition
uint8_t pcf8563_init(pcf8563_handle_t *handle)
initialize the chip
struct pcf8563_info_s pcf8563_info_t
pcf8563 information structure definition
uint8_t pcf8563_get_hour_alarm(pcf8563_handle_t *handle, uint8_t *hour)
get hour alarm
uint8_t pcf8563_get_clock_out_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get clock out enable status
pcf8563_clock_out_t
pcf8563 clock out enumeration definition
uint8_t pcf8563_get_timer_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get timer interrupt status
uint8_t pcf8563_set_time(pcf8563_handle_t *handle, pcf8563_time_t *t)
set the current time
uint8_t pcf8563_get_day_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the day alarm status
uint8_t pcf8563_get_minute_alarm(pcf8563_handle_t *handle, uint8_t *minute)
get minute alarm
struct pcf8563_time_s pcf8563_time_t
pcf8563 time structure definition
uint8_t pcf8563_get_day_alarm(pcf8563_handle_t *handle, uint8_t *day)
get day alarm
uint8_t pcf8563_get_clock_out(pcf8563_handle_t *handle, pcf8563_clock_out_t *clk)
get clock out
uint8_t pcf8563_get_timer_value(pcf8563_handle_t *handle, uint8_t *value)
get timer value
uint8_t pcf8563_irq_handler(pcf8563_handle_t *handle)
irq handler
uint8_t pcf8563_set_alarm_interrupt(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable alarm interrupt
uint8_t pcf8563_set_week_alarm(pcf8563_handle_t *handle, uint8_t week)
set week alarm
uint8_t pcf8563_set_day_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable day alarm
uint8_t pcf8563_set_minute_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable minute alarm
uint8_t pcf8563_set_rtc_stop(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable rtc stop
struct pcf8563_handle_s pcf8563_handle_t
pcf8563 handle structure definition
uint8_t pcf8563_set_interrupt_mode(pcf8563_handle_t *handle, pcf8563_interrupt_mode_t mode)
set the interrupt mode
uint8_t pcf8563_get_power_on_reset(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the power on reset status
pcf8563_interrupt_event_t
pcf8563 interrupt event enumeration definition
uint8_t pcf8563_get_timer_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get timer enable status
uint8_t pcf8563_set_timer_value(pcf8563_handle_t *handle, uint8_t value)
set timer value
uint8_t pcf8563_get_week_alarm_enable(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the week alarm status
uint8_t pcf8563_get_time(pcf8563_handle_t *handle, pcf8563_time_t *t)
get the current time
uint8_t pcf8563_get_test_mode(pcf8563_handle_t *handle, pcf8563_bool_t *enable)
get the test mode status
uint8_t pcf8563_clear_status(pcf8563_handle_t *handle, pcf8563_interrupt_event_t event)
clear status
uint8_t pcf8563_set_power_on_reset(pcf8563_handle_t *handle, pcf8563_bool_t enable)
enable or disable power on reset
@ PCF8563_INTERRUPT_EVENT_TIMER
@ PCF8563_INTERRUPT_EVENT_ALARM
uint8_t pcf8563_get_reg(pcf8563_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t pcf8563_set_reg(pcf8563_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v