foxBMS  1.2.0
The foxBMS Battery Management System API Documentation
pex.h File Reference

Header for the driver for the NXP PCA9539 port expander module. More...

#include "pex_cfg.h"
Include dependency graph for pex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PEX_PIN_LOW   (0u)
 
#define PEX_PIN_HIGH   (1u)
 

Functions

void PEX_Initialize (void)
 initialize local variable containing state of port expander. 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...
 
void PEX_Trigger (void)
 implements reading/writing to the port expander registers. More...
 

Detailed Description

Header for the 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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2021-08-02 (date of creation)
Updated
2021-10-04 (date of last update)
Prefix
PEX

Definition in file pex.h.

Macro Definition Documentation

◆ PEX_PIN_HIGH

#define PEX_PIN_HIGH   (1u)

Port expander pin high levels in registers

Definition at line 65 of file pex.h.

◆ PEX_PIN_LOW

#define PEX_PIN_LOW   (0u)

Port expander pin high levels in registers

Definition at line 64 of file pex.h.

Function Documentation

◆ PEX_GetPin()

uint8_t PEX_GetPin ( uint8_t  portExpander,
uint8_t  pin 
)

get pin state of port expander pins.

Returns
pin state: PEX_PIN_LOW or PEX_PIN_HIGH

Definition at line 350 of file pex.c.

Here is the call graph for this function:

◆ PEX_Initialize()

void PEX_Initialize ( void  )

initialize local variable containing state of port expander.

In the datasheet, 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 Datasheet: Rev. 9 - 8 November 2017, Table 7 and 8

Default state of polarity inversion registers Datasheet: Rev. 9 - 8 November 2017, Table 9 and 10

Default state of direction registers Datasheet: Rev. 9 - 8 November 2017, Table 11 and 12

Definition at line 279 of file pex.c.

◆ PEX_ResetPin()

void PEX_ResetPin ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin to low.

Parameters
portExpanderport expander number
pinpin number

Definition at line 335 of file pex.c.

Here is the call graph for this function:

◆ PEX_SetPin()

void PEX_SetPin ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin to high.

Parameters
portExpanderport expander number
pinpin number

Definition at line 320 of file pex.c.

Here is the call graph for this function:

◆ PEX_SetPinDirectionInput()

void PEX_SetPinDirectionInput ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin direction to input.

Parameters
portExpanderport expander number
pinpin number

Definition at line 378 of file pex.c.

Here is the call graph for this function:

◆ PEX_SetPinDirectionOutput()

void PEX_SetPinDirectionOutput ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin to input.

Parameters
portExpanderport expander number
pinpin number

Definition at line 393 of file pex.c.

Here is the call graph for this function:

◆ PEX_SetPinPolarityInverted()

void PEX_SetPinPolarityInverted ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin polarity to inverted.

Parameters
portExpanderport expander number
pinpin number

Definition at line 409 of file pex.c.

Here is the call graph for this function:

◆ PEX_SetPinPolarityRetained()

void PEX_SetPinPolarityRetained ( uint8_t  portExpander,
uint8_t  pin 
)

sets pin polarity to retained.

Parameters
portExpanderport expander number
pinpin number

Definition at line 424 of file pex.c.

Here is the call graph for this function:

◆ PEX_Trigger()

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 301 of file pex.c.

Here is the call graph for this function: