nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Data Structures | Public Member Functions | Static Public Attributes
nrfcxx::misc::sx1509b Class Reference

Abstraction around the Semtex SX1509B Level-Shifting GPIO Extender. More...

#include <nrfcxx/misc/sx1509b.hpp>

Data Structures

struct  gpio_regs_type
 Structure for SX1509 registers that are controlled. More...
 
struct  iface_config_type
 The pieces you need to talk to the device. More...
 
struct  led_pwm_type
 Extended configuration for fade-capable pins. More...
 
struct  led_type
 Basic structure for LED configuration. More...
 

Public Member Functions

const iface_config_typeiface_config () const
 Access the interface configuration for the device.
 
const gpio_regs_typegpio_cache () const noexcept
 Access the internal cache of GPIO registers.
 
uint16_t led_driver_cache () const
 Access the internal cache of LEDDriverEnable.
 
uint8_t clock_cache () const
 Access the internal cache of Clock.
 
uint8_t misc_cache () const
 Access the internal cache of Misc.
 
int reload_cache () noexcept
 Read all locally cached registers from the device. More...
 
unsigned int configuration (unsigned int psel) const noexcept
 Return the GPIO pin configuration for the given IOX pin. More...
 
int configure (unsigned int psel, unsigned int pin_cnf, int initial=-1) noexcept
 Change the GPIO pin configuration for the given IOX pin. More...
 
int multiconfigure (uint16_t out_set, uint16_t out_clear, uint16_t pull_down, uint16_t pull_up=0) noexcept
 Configure multiple pins at once. More...
 
 sx1509b (iface_config_type &ifc, unsigned int addr=0) noexcept
 Instantiate the device. More...
 
int hw_reset () noexcept
 Reset the device to its power-on state via RESETn. More...
 
int sw_reset () noexcept
 Reset the device to its power-on state via software command. More...
 
int clock () const noexcept
 Read the Clock register from the SX1509B. More...
 
int clock (uint8_t value) noexcept
 Set the Clock register in the SX1509B. More...
 
int misc () const noexcept
 Read the Misc register from the SX1509B. More...
 
int misc (uint8_t value) noexcept
 Set the Misc register in the SX1509B. More...
 
int configure_as_leds (uint16_t leds, bool source_current=false) noexcept
 Configure a set of pins for LED operations. More...
 
int led_configuration (unsigned int psel, led_type &cfg) const noexcept
 Read the LED configuration for the given pin. More...
 
int led_configuration (unsigned int psel, led_pwm_type &cfg) const noexcept
 Set the LED configuration for the given pin. More...
 
int led_configure (unsigned int psel, const led_type &cfg) const noexcept
 Set the LED configuration for the given pin. More...
 
int led_configure (unsigned int psel, const led_pwm_type &cfg) const noexcept
 Set the LED configuration for the given pin. More...
 
int output_sct (uint16_t set, uint16_t clear) noexcept
 Multi-signal set, clear, and toggle API. More...
 

Static Public Attributes

static constexpr auto RegClock_FREQ_Pos = 5U
 
static constexpr uint16_t RegClock_FREQ_Msk = 0x03 << RegClock_FREQ_Pos
 
static constexpr uint16_t RegClock_FREQ_Off = 0
 
static constexpr uint16_t RegClock_FREQ_External = 1
 
static constexpr uint16_t RegClock_FREQ_2MHz = 2
 
static constexpr auto RegClock_OSCIO_Pos = 4U
 
static constexpr uint16_t RegClock_OSCIO_Msk = 0x01 << RegClock_OSCIO_Pos
 
static constexpr uint16_t RegClock_OSCIO_Input = 0
 
static constexpr uint16_t RegClock_OSCIO_Output = 1
 
static constexpr auto RegClock_OUTFREQ_Pos = 0U
 
static constexpr uint16_t RegClock_OUTFREQ_Msk = 0x0F << RegClock_OUTFREQ_Pos
 
static constexpr uint16_t RegClock_OUTFREQ_Low = 0
 
static constexpr uint16_t RegClock_OUTFREQ_High = 0x0F
 
static constexpr auto RegMisc_LEDB_Pos = 7U
 
static constexpr uint16_t RegMisc_LEDB_Msk = 1U << RegMisc_LEDB_Pos
 
static constexpr uint16_t RegMisc_LEDB_Linear = 0
 
static constexpr uint16_t RegMisc_LEDB_Logarithmic = 1
 
static constexpr auto RegMisc_LEDFREQ_Pos = 4U
 
static constexpr uint16_t RegMisc_LEDFREQ_Msk = 0x07U << RegMisc_LEDFREQ_Pos
 
static constexpr uint16_t RegMisc_LEDFREQ_Off = 0
 
static constexpr auto RegMisc_LEDA_Pos = 3U
 
static constexpr uint16_t RegMisc_LEDA_Msk = 1U << RegMisc_LEDA_Pos
 
static constexpr uint16_t RegMisc_LEDA_Linear = 0
 
static constexpr uint16_t RegMisc_LEDA_Logarithmic = 1
 
static constexpr auto RegMisc_NRESET_Pos = 2U
 
static constexpr uint16_t RegMisc_NRESET_Msk = 1U << RegMisc_NRESET_Pos
 
static constexpr uint16_t RegMisc_NRESET_POR = 0
 
static constexpr uint16_t RegMisc_NRESET_ResetCounters = 1
 
static constexpr auto RegMisc_AUTOINC_Pos = 1U
 
static constexpr uint16_t RegMisc_AUTOINC_Msk = 1U << RegMisc_AUTOINC_Pos
 
static constexpr uint16_t RegMisc_AUTOINC_On = 0
 
static constexpr uint16_t RegMisc_AUTOINC_Off = 1
 
static constexpr auto RegMisc_AUTOCLR_Pos = 0U
 
static constexpr uint16_t RegMisc_AUTOCLR_Msk = 1U << RegMisc_AUTOCLR_Pos
 
static constexpr uint16_t RegMisc_AUTOCLR_On = 0
 
static constexpr uint16_t RegMisc_AUTOCLR_Off = 1
 
static constexpr auto RegTOnX_TOn_Pos = 0U
 
static constexpr uint16_t RegTOnX_TOn_Msk = 0x1F << RegTOnX_TOn_Pos
 
static constexpr auto RegOffX_TOff_Pos = 3U
 
static constexpr uint16_t RegOffX_TOff_Msk = 0x1F << RegOffX_TOff_Pos
 
static constexpr auto RegOffX_IOff_Pos = 0U
 
static constexpr uint16_t RegOffX_IOff_Msk = 0x07 << RegOffX_IOff_Pos
 

Detailed Description

Abstraction around the Semtex SX1509B Level-Shifting GPIO Extender.

Note
At this time only basic GPIO and LED driver functionality is supported.
See also
https://www.semtech.com/products/smart-sensing/io-expanders/sx1509b

Constructor & Destructor Documentation

◆ sx1509b()

nrfcxx::misc::sx1509b::sx1509b ( iface_config_type ifc,
unsigned int  addr = 0 
)
noexcept

Instantiate the device.

Parameters
ifcreference to an externally owned struct providing the resources required to communicate with the device.
addrthe device address as controlled by the A0 and A1 pins, value in the range 0 to 3.

Member Function Documentation

◆ clock() [1/2]

int nrfcxx::misc::sx1509b::clock ( ) const
noexcept

Read the Clock register from the SX1509B.

Note
The cached value will not be updated.

◆ clock() [2/2]

int nrfcxx::misc::sx1509b::clock ( uint8_t  value)
noexcept

Set the Clock register in the SX1509B.

On success the cached value will also be updated.

◆ configuration()

unsigned int nrfcxx::misc::sx1509b::configuration ( unsigned int  psel) const
noexcept

Return the GPIO pin configuration for the given IOX pin.

The value is compatible with Nordic GPIOs, and is derived from the internal cache of the SX1509B register set.

Parameters
pselthe IOX pin index, in the range 0..15.
Returns
the Nordig GPIO pin configuration inferred from the SX1509B register cache.

◆ configure()

int nrfcxx::misc::sx1509b::configure ( unsigned int  psel,
unsigned int  pin_cnf,
int  initial = -1 
)
noexcept

Change the GPIO pin configuration for the given IOX pin.

This translates the standard Nordic GPIO pin flags into SX1509B register mutations through this process:

  • If the pin had been configured via configure_as_leds() its LEDDriverEnable bit will be cleared;
  • If an initial value is provided, the corresponding bit in Data will be updated if necessary;
  • INPUT controls InputDisable;
  • DIR controls Dir;
  • PULL controls PullUp and PullDown;
  • SENSE is not used;
  • DRIVE is not used;
  • OpenDrain is cleared
Parameters
pselthe IOX pin index, in the range 0..15.
pin_cnfthe Nordic GPIO pin configuration to emulate.
initialif zero ensure the Data bit is cleared before configuration; if positive ensure the Data is set before configuration; if negative the Data register is not affected by configuration.
Returns
a non-negative value on success, or a negative error code.

◆ configure_as_leds()

int nrfcxx::misc::sx1509b::configure_as_leds ( uint16_t  leds,
bool  source_current = false 
)
noexcept

Configure a set of pins for LED operations.

Parameters
ledsbit mask identifying pins that should be enabled the LED driver.
source_currentif true the SX1509B will be configured to drive the LED pins as normal outputs. If false OpenDrain will be enabled for the LED pins.
Returns
a non-negative value on success, or a negative error code.

◆ hw_reset()

int nrfcxx::misc::sx1509b::hw_reset ( )
noexcept

Reset the device to its power-on state via RESETn.

This works as long as misc() is not configured to use the RESETn signal to synchronize PWM counters.

Returns
a non-negative duration in ms to wait until the device will have completed reset, or a negative error code.

◆ led_configuration() [1/2]

int nrfcxx::misc::sx1509b::led_configuration ( unsigned int  psel,
led_pwm_type cfg 
) const
noexcept

Set the LED configuration for the given pin.

Parameters
pselthe IOX pin index. The pin need not be configured for LED use.
cfgwhere to store the fade-capable configuration to use. If the pin does not support fade the call will return an error.
Returns
a non-negative value on success, or a negative error code.

◆ led_configuration() [2/2]

int nrfcxx::misc::sx1509b::led_configuration ( unsigned int  psel,
led_type cfg 
) const
noexcept

Read the LED configuration for the given pin.

Parameters
pselthe IOX pin index. The pin need not be configured for LED use.
cfgwhere to store the non-fade configuration to use.
Returns
a non-negative value on success, or a negative error code.

◆ led_configure() [1/2]

int nrfcxx::misc::sx1509b::led_configure ( unsigned int  psel,
const led_pwm_type cfg 
) const
noexcept

Set the LED configuration for the given pin.

Parameters
pselthe IOX pin index. The pin need not be configured for LED use.
cfgthe fade configuration to use. If the pin does not support fade the call will return an error.
Returns
a non-negative value on success, or a negative error code.

◆ led_configure() [2/2]

int nrfcxx::misc::sx1509b::led_configure ( unsigned int  psel,
const led_type cfg 
) const
noexcept

Set the LED configuration for the given pin.

Note
If this is used to configure a LED that supports fade the rise and fall times will not be affected.
Parameters
pselthe IOX pin index. The pin need not be configured for LED use.
cfgthe non-fade configuration to use.
Returns
a non-negative value on success, or a negative error code.

◆ misc() [1/2]

int nrfcxx::misc::sx1509b::misc ( ) const
noexcept

Read the Misc register from the SX1509B.

Note
The cached value will not be updated.

◆ misc() [2/2]

int nrfcxx::misc::sx1509b::misc ( uint8_t  value)
noexcept

Set the Misc register in the SX1509B.

On success the cached value will also be updated.

◆ multiconfigure()

int nrfcxx::misc::sx1509b::multiconfigure ( uint16_t  out_set,
uint16_t  out_clear,
uint16_t  pull_down,
uint16_t  pull_up = 0 
)
noexcept

Configure multiple pins at once.

Pins where the corresponding bit is not set in out_set or out_clear are configured as inputs.

Note
This function is intended to be used immediately after reset. The only registers configured are: PullUp, PullDown, Dir, Data.
Parameters
out_setbits identifying pins that are to be configured as output, normal drive, initially set.
out_clearbits identifying pins that are to be configured as output, normal drive, initially clear. Any bit set here and in out_set will be treated as if only in out_set.
pull_downbits identifying pins that are to be configured as pull-down. Both input and output pins will be configured.
pull_upbits identifying pins that are to be configured as pull-up. Both input and output pins will be configured. Any bit set here and in pull_down will be treated as if only in pull_down.
Returns
non-negative on success, or a negative error code.

◆ output_sct()

int nrfcxx::misc::sx1509b::output_sct ( uint16_t  set,
uint16_t  clear 
)
noexcept

Multi-signal set, clear, and toggle API.

If a bit is set in both set and clear its current value is toggled. If no bits are set in set or clear the current IOX output configuration is returned from cache.

Parameters
setbits identifying IOX outputs that should be high.
clearbits identifying IOX outputs that should be low.
Returns
a non-negative value provides the current setting for all IOX outputs. A negative value indicates a failure to configure the outputs.

◆ reload_cache()

int nrfcxx::misc::sx1509b::reload_cache ( )
noexcept

Read all locally cached registers from the device.

This may be used if you believe gpio_cache() or other local storage is not accurate.

Warning
Be aware that the gpio_regs_type::data carries the input signal, not the output setting, if gpio_regs_type::input_disable is clear. This may result in confusing values if the signal connected to the pin is pulled in the opposite direction.
Returns
non-negative on success, or a negative error code.

◆ sw_reset()

int nrfcxx::misc::sx1509b::sw_reset ( )
noexcept

Reset the device to its power-on state via software command.

Returns
a non-negative duration in ms to wait until the device will have completed reset, or a negative error code.

The documentation for this class was generated from the following file: