-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDS_GPMS.c
68 lines (46 loc) · 2.16 KB
/
DS_GPMS.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
/*!\file DS_GPMS.c
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief DS-GPM.S Driver
** \details DS-GPM.S: 99 Channel Positioning System (GPS + GLONASS) Shield
**/
/****************************************************************/
#include "DS_GPMS.h"
#if defined(HAL_I2C_MODULE_ENABLED)
#if defined(I2C_GPMS)
/****************************************************************/
static const I2C_slave_t GPMS_defaults = { { pNull, 0, I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_FM }, 0, HAL_OK, true, false };
static I2C_slave_t GPMS_hal; //!< GPMS Slave structure
/****************************************************************/
__WEAK FctERR GPMS_Init(void)
{
FctERR err;
I2C_PERIPHERAL_SET_DEFAULTS_SINGLETON(GPMS);
err = I2C_slave_init(&GPMS_hal, I2C_GPMS, GPMS_BASE_ADDR, GPMS_hal.cfg.timeout);
if (!err) { err = GPMS_Init_Sequence(); }
if (err) { I2C_set_enable(&GPMS_hal, false); }
return err;
}
/****************************************************************/
FctERR NONNULL__ GPMS_Write(const uint8_t * data, const uint16_t addr, const uint16_t nb)
{
if (!I2C_is_enabled(&GPMS_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if ((addr + nb) > GPMS__IO_PORT_OUTPUT + 1) { return ERROR_OVERFLOW; } // More bytes than registers
I2C_set_busy(&GPMS_hal, true);
GPMS_hal.status = HAL_I2C_Mem_Write(GPMS_hal.cfg.bus_inst, GPMS_hal.cfg.addr, addr, GPMS_hal.cfg.mem_size, (uint8_t *) data, nb, GPMS_hal.cfg.timeout);
I2C_set_busy(&GPMS_hal, false);
return HALERRtoFCTERR(GPMS_hal.status);
}
FctERR NONNULL__ GPMS_Read(uint8_t * data, const uint16_t addr, const uint16_t nb)
{
if (!I2C_is_enabled(&GPMS_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if ((addr + nb) > GPMS__STATUS + 1) { return ERROR_OVERFLOW; } // More bytes than registers
I2C_set_busy(&GPMS_hal, true);
GPMS_hal.status = HAL_I2C_Mem_Read(GPMS_hal.cfg.bus_inst, GPMS_hal.cfg.addr, addr, GPMS_hal.cfg.mem_size, data, nb, GPMS_hal.cfg.timeout);
I2C_set_busy(&GPMS_hal, false);
return HALERRtoFCTERR(GPMS_hal.status);
}
/****************************************************************/
#endif
#endif
/****************************************************************/