-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNCA9595_proc.c
71 lines (50 loc) · 1.66 KB
/
NCA9595_proc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*!\file NCA9595_proc.c
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief NCA9595 Driver procedures
** \details NCA9595: Low-voltage 16-bit I²C and SMBus I/O expander
**/
/****************************************************************/
#include "NCA9595.h"
#if defined(HAL_I2C_MODULE_ENABLED)
#if defined(I2C_NCA9595)
/****************************************************************/
// std libs
//#include <stdlib.h>
/****************************************************************/
NCA9595_t NCA9595[I2C_NCA9595_NB] = { 0 };
/****************************************************************/
__WEAK FctERR NONNULL__ NCA9595_Init_Sequence(NCA9595_t * const pCpnt)
{
UNUSED(pCpnt);
return ERROR_OK;
}
/****************************************************************/
__WEAK FctERR NONNULL__ NCA9595_handler(NCA9595_t * const pCpnt)
{
FctERR err;
err = NCA9595_Read_Register(pCpnt, &pCpnt->NCA9595_in.Word, NCA9595__InputPorts);
if (err) { return err; }
if (pCpnt->cfg.NCA9595_Cfg.Word != 0xFFFF) // Not all GPIOs set to inputs
{
err = NCA9595_Write_Outputs(pCpnt, pCpnt->NCA9595_out.Word);
if (err) { return err; }
}
#if defined(VERBOSE)
const uint8_t idx = pCpnt - NCA9595;
printf("NCA9595 id%d: Inputs %x", idx, pCpnt->NCA9595_in.Word);
#endif
return ERROR_OK;
}
__WEAK FctERR NONNULL__ NCA9595_handler_it(NCA9595_t * const pCpnt)
{
FctERR err;
bool interrupt;
err = NCA9595_INT_GPIO_Get(pCpnt, &interrupt);
if ((!err) && interrupt) { err = NCA9595_handler(pCpnt); }
return err;
}
/****************************************************************/
#endif
#endif
/****************************************************************/