Initializing the Board and Pin Configuration
Initializing the Board
When using a Cow Pi board, a single function call is sufficient to configure all pins and fully initialize the board if no Expansion Options are used. (If expansions are used, their pins must must be configured separately, as must their initialization.)
The cowpi_setup() function does three things:
It initializes the standard input/output/error FILE streams at the specified bitrate
It configures the display module using the same
cowpi_display_module_tandcowpi_display_module_protocol_targuments as the CowPi_stdio library’scowpi_add_display_module()function - The function returns a pointer to the display module’s FILE streamIt assigns the peripheral inputs and outputs to the microcontroller pins appropriate to your particular Cow Pi board, and it configures the pins accordingly
-
FILE *cowpi_setup(unsigned long console_bitrate, cowpi_display_module_t display_module, cowpi_display_module_protocol_t communication_protocol)
Configures the microcontroller’s pins for the expected hardware setup, configures
stdoutandstdinto use the USB-based serial interface between the microcontroller and the host computer, and configures the library to work with the specified display module and communication protocol.If the Morse Code “font” is available, then
stderrwill use Morse Code on the right LED. Otherwise,stderrwill be aliased tostdout.If the USB-based serial interface should not be configured, then set the
console_bitrateto 0. If there is not yet a display module, then set thedisplay_moduleto{.display_module = NO_MODULE}. If there is not yet a display module (and the communication protocol’s pins are not otherwise used) then you may assigncommunication_protocolto{.protocol = NO_PROTOCOL}.See also
cowpi_stdio_setup()in CowPi_stdioSee also
cowpi_add_display_module()in CowPi_stdio- Parameters:
console_bitrate – the serial interface’s bitrate, or
0if the serial interface should not be configureddisplay_module – the display module’s details
communication_protocol – the communication protocol’s details
- Returns:
a pointer to a
FILEstream for the display module, orNULLif a stream could not be created
Custom Pin Configuration
The cowpi_setup() configures the pins for the inputs and outputs on the Cow Pi board,
but pins used by other inputs and outputs must be configured separately.
The CowPi library provides framework-independent functions to configure pins as output pins, high-impedance (“floating”) input pins, or pulled-up input pins.
(Portability aside, we very strongly recommend using these functions to reduce some guesswork by other functions in the library.)
These functions take a single argument: a bit vector that identifies which pin(s) are to be configured. If bit n is a 1, then pin n will be configured by the function. If bit n is a 0, then pin n’s existing configuration will be left unchanged.
-
void cowpi_set_output_pins(uint32_t pins)
Configures the specified pin to be output pins.
The
pinsargument is used to specify which pins will be output pins. Bit0 corresponds to Pin 0, Bit1 corresponds to Pin 1, and so on. A 1 in a particular bit indicates that the corresponding pin should be an output pin, overriding any previous configuration for that pin. If more than one bit has a 1, then each of the corresponding pins will be output pins. The configuration of any pin whose corresponding bit bit is 0 will be unchanged, regardless of whether that pin had been previously set as an input or output pin.- Parameters:
pins – A bit vector specifying which pins will be output pins
-
void cowpi_set_floating_input_pins(uint32_t pins)
Configures the specified pin to be input pins with high impedance to both the microprocessor’s reference voltage and ground; that is, their input values will float unless driven high or low by a peripheral device.
The
pinsargument is used to specify which pins will be input pins. Bit0 corresponds to Pin 0, Bit1 corresponds to Pin 1, and so on. A 1 in a particular bit indicates that the corresponding pin should be a floating input pin, overriding any previous configuration for that pin. If more than one bit has a 1, then each of the corresponding pins will be floating input pins. The configuration of any pin whose corresponding bit bit is 0 will be unchanged, regardless of whether that pin had been previously set as an input or output pin, and regardless of whether it had been previously set to float or tied to a pullup or pulldown resistor.- Parameters:
pins – A bit vector specifying which pins will be floating input pins
-
void cowpi_set_pullup_input_pins(uint32_t pins)
Configures the specified pin to be input pins connected to a pullup resistor that is internal to the microcontroller; that is, their input values will be high unless driven low by a peripheral device.
The
pinsargument is used to specify which pins will be input pins. Bit0 corresponds to Pin 0, Bit1 corresponds to Pin 1, and so on. A 1 in a particular bit indicates that the corresponding pin should be a pulled-up input pin, overriding any previous configuration for that pin. If more than one bit has a 1, then each of the corresponding pins will be pulled-up input pins. The configuration of any pin whose corresponding bit bit is 0 will be unchanged, regardless of whether that pin had been previously set as an input or output pin, and regardless of whether it had been previously set to float or tied to a pullup or pulldown resistor.- Parameters:
pins – A bit vector specifying which pins will be floating input pins