Nut/OS  4.10.3
API Reference
SPI Digital I/O

SPI controlled digital input and output ports. More...

Collaboration diagram for SPI Digital I/O:

Functions

uint32_t SpiDigitalGet (ureg_t num)
 Query digital inputs.
void SpiDigitalSet (ureg_t num, uint32_t bits)
 Set digital outputs.
void SpiDigitalInit (ureg_t *inputs, ureg_t *outputs)
 Initialize the digital I/O shift register interface.

Detailed Description

SPI controlled digital input and output ports.

This simple driver supports digital I/O ports like relay outputs and optocoupler inputs.


Function Documentation

uint32_t SpiDigitalGet ( ureg_t  num)

Query digital inputs.

SpiDigitalInit() must have been called by the application before calling this function.

This routine does not check the validity of the parameter.

Parameters:
numNumber of bits to query, typically 8, 16, 24 or the maximum value of 32. This number should exactly match the number of input pins. If it is lower, only the most significant bits are returned. However, this may be used by an application to scan these bits more often with reduced overhead.
Returns:
Binary value of the requested inputs. Only the specified number of bits are used. Bit 0 is the one, which has been shifted out last.

Definition at line 272 of file spidigio.c.

References bit_is_set, cbi, sbi, SPIDIGIO_LDI_BIT, SPIDIGIO_LDI_PORT, SPIDIGIO_SIN_BIT, SPIDIGIO_SIN_PIN, SPIDIGIO_SOUT_BIT, and SPIDIGIO_SOUT_PORT.

void SpiDigitalSet ( ureg_t  num,
uint32_t  bits 
)

Set digital outputs.

SpiDigitalInit() must have been called by the application before calling this function.

This routine does not check the validity of any parameter.

Parameters:
numNumber of bits to set, typically 8, 16, 24 or 32, which is the maximum. The number must not be lower than the number of shift register output bits.
bitsThe bit value to set. Only the number of bits specified are used, of which the most significant bit is shifted in first.

Definition at line 326 of file spidigio.c.

References cbi, sbi, SPIDIGIO_LDO_BIT, SPIDIGIO_LDO_PORT, SPIDIGIO_SOUT_BIT, and SPIDIGIO_SOUT_PORT.

void SpiDigitalInit ( ureg_t inputs,
ureg_t outputs 
)

Initialize the digital I/O shift register interface.

This routine must be called before using the interface.

Automatically detects the number of digital inputs and outputs. However, the method used is limited and may fail on fast changing inputs. The application should check the result for plausibility. It is save to call the routine more than once.

Parameters:
inputsPointer to an 8-bit value, where the number of detected inputs will be stored.
outputsPointer to an 8-bit value, where the number of detected outputs will be stored.

Definition at line 471 of file spidigio.c.

References cbi, NutGetCpuClock(), sbi, SPIDIGIO_LDI_BIT, SPIDIGIO_LDI_DDR, SPIDIGIO_LDI_PORT, SPIDIGIO_LDO_BIT, SPIDIGIO_LDO_DDR, SPIDIGIO_LDO_PORT, SPIDIGIO_SCLK_BIT, SPIDIGIO_SCLK_DDR, SPIDIGIO_SCLK_PORT, SPIDIGIO_SIN_BIT, SPIDIGIO_SIN_DDR, SPIDIGIO_SIN_PORT, SPIDIGIO_SOUT_BIT, and SPIDIGIO_SOUT_DDR.

Here is the call graph for this function: