foxBMS - Unit Tests
1.4.1
The foxBMS Unit Tests API Documentation
|
Driver for the NXP PCA9539 port expander module. More...
Go to the source code of this file.
Macros | |
#define | PEX_NR_OF_PORTS_PER_REGISTER (8u) |
#define | PEX_DEFAULT_VALUE_ALL_1 (0xFFu) |
#define | PEX_DEFAULT_VALUE_ALL_0 (0x0u) |
#define | PEX_INPUT_PORT0_REGISTER_ADDRESS (0x0u) |
#define | PEX_OUTPUT_PORT0_REGISTER_ADDRESS (0x2u) |
#define | PEX_POL_INV_PORT0_REGISTER_ADDRESS (0x4u) |
#define | PEX_DIRECTION_PORT0_REGISTER_ADDRESS (0x6u) |
#define | PEX_PIN_POLARITY_RETAINED (0u) |
#define | PEX_PIN_POLARITY_INVERTED (1u) |
#define | PEX_PIN_DIRECTION_OUTPUT (0u) |
#define | PEX_PIN_DIRECTION_INPUT (1u) |
Functions | |
static STD_RETURN_TYPE_e | PEX_ReadInputs (void) |
reads input state of port expander pins over I2C. More... | |
static STD_RETURN_TYPE_e | PEX_WriteOutputs (void) |
sets output state of port expander pins over I2C. More... | |
static STD_RETURN_TYPE_e | PEX_WriteConfigPolarity (void) |
sets polarity inversion state of port expander pins over I2C. More... | |
static STD_RETURN_TYPE_e | PEX_WriteConfigDirection (void) |
sets direction of port expander pins over I2C. More... | |
static void | PEX_CopyToLocalVariable (void) |
copies values from the externally available variables to the local ones. More... | |
static void | PEX_GetFromLocalVariable (void) |
copies values from the local variables to the externally available ones. More... | |
void | PEX_Initialize (void) |
initialize local variable containing state of port expander. More... | |
void | PEX_Trigger (void) |
implements reading/writing to the port expander registers. More... | |
void | PEX_SetPin (uint8_t portExpander, uint8_t pin) |
sets pin to high. More... | |
void | PEX_ResetPin (uint8_t portExpander, uint8_t pin) |
sets pin to low. More... | |
uint8_t | PEX_GetPin (uint8_t portExpander, uint8_t pin) |
get pin state of port expander pins. More... | |
void | PEX_SetPinDirectionInput (uint8_t portExpander, uint8_t pin) |
sets pin direction to input. More... | |
void | PEX_SetPinDirectionOutput (uint8_t portExpander, uint8_t pin) |
sets pin to input. More... | |
void | PEX_SetPinPolarityInverted (uint8_t portExpander, uint8_t pin) |
sets pin polarity to inverted. More... | |
void | PEX_SetPinPolarityRetained (uint8_t portExpander, uint8_t pin) |
sets pin polarity to retained. More... | |
Driver for the NXP PCA9539 port expander module.
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
Definition in file pex.c.
#define PEX_DIRECTION_PORT0_REGISTER_ADDRESS (0x6u) |
#define PEX_INPUT_PORT0_REGISTER_ADDRESS (0x0u) |
#define PEX_NR_OF_PORTS_PER_REGISTER (8u) |
#define PEX_OUTPUT_PORT0_REGISTER_ADDRESS (0x2u) |
#define PEX_PIN_DIRECTION_INPUT (1u) |
#define PEX_PIN_DIRECTION_OUTPUT (0u) |
#define PEX_PIN_POLARITY_INVERTED (1u) |
#define PEX_PIN_POLARITY_RETAINED (0u) |
#define PEX_POL_INV_PORT0_REGISTER_ADDRESS (0x4u) |
|
static |
|
static |
uint8_t PEX_GetPin | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
get pin state of port expander pins.
Definition at line 351 of file pex.c.
void PEX_Initialize | ( | void | ) |
initialize local variable containing state of port expander.
In the data sheet, pins are grouped in two sets, numbered from 00 to 07 and from 10 to 17. Each set is handled by a separate register, so pin 00 is numbered 0, pin 01 is numbered 01, .., pin 07 is numbered 07. But also pin 10 is numbered 0, pin 11 is numbered 01, .., pin 17 is numbered 07. Using defines from 0 to 15, it is possible to get with pin number which register has to be addressed: 0 to 7 means register for 00 to 07, 8 to 15 means register for 10 to 17. Applying (pin%8) for 8 to 15 gives 0 to 7, so the numbering in register is obtained immediately.
Default state of output registers data sheet: Rev. 9 - 8 November 2017, Table 7 and 8
Default state of polarity inversion registers data sheet: Rev. 9 - 8 November 2017, Table 9 and 10
Default state of direction registers data sheet: Rev. 9 - 8 November 2017, Table 11 and 12
|
static |
reads input state of port expander pins over I2C.
Definition at line 167 of file pex.c.
void PEX_ResetPin | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_SetPin | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_SetPinDirectionInput | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_SetPinDirectionOutput | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_SetPinPolarityInverted | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_SetPinPolarityRetained | ( | uint8_t | portExpander, |
uint8_t | pin | ||
) |
void PEX_Trigger | ( | void | ) |
implements reading/writing to the port expander registers.
This function reads the desired port expander state (outputs, configuration) from the externally available variables and stores it in the local variable. It then applies this state to the devices via the I2C bus. It reads the pin input state via the I2C bus and writes it to the externally available port expander state.
Definition at line 302 of file pex.c.
|
static |
sets direction of port expander pins over I2C.
Direction Port 0 as address, next read register will be Direction Port 1 data sheet: Rev. 9 - 8 November 2017 Figure 10: one register pair can be written in one transaction
Definition at line 229 of file pex.c.
|
static |
sets polarity inversion state of port expander pins over I2C.
Inversion Polarity Port 0 as address, next read register will be Inversion Polarity Port 1 data sheet: Rev. 9 - 8 November 2017 Figure 10: one register pair can be written in one transaction
Definition at line 210 of file pex.c.
|
static |
sets output state of port expander pins over I2C.
Outport Port 0 as address, next read register will be Output Port 1 data sheet: Rev. 9 - 8 November 2017 Figure 10: one register pair can be written in one transaction
Definition at line 191 of file pex.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |