SAE Teensy ECU
IIT SAE Microcontroller programming
|
Update, set, and get predefined pin values. More...
Go to the source code of this file.
Namespaces | |
namespace | Pins |
Get and set values to predefined pins. | |
Macros | |
#define | PINS_ANALOG_RES CONF_PINS_ANALOG_WRITE_RESOLUTION |
The current target bit resolution of the ECU, set by PinConfig.def. | |
#define | PINS_ANALOG_MAX pwrtwo(PINS_ANALOG_RES) |
The maximum analog value, given the current PINS_ANALOG_RES. | |
#define | PINS_ANALOG_HIGH (PINS_ANALOG_MAX - 1) |
The high analog value, will not force an analog output to lock onto a high state, as PINS_ANALOG_MAX does. | |
#define | PINS_ANALOG_MIN 0 |
The minimum analog value. Its zero, I think it will always be zero. Not sure why i needed this. | |
#define | PINS_VOLT_TO_ANALOG(x) (int)min(max((x / 5) * PINS_ANALOG_HIGH, PINS_ANALOG_MIN), PINS_ANALOG_HIGH) |
Maps Voltages 0-5v to an appropriate analog value. | |
Typedefs | |
typedef void(* | Pins::PinHandler) (uint8_t CAN_GPIO_Pin, int &value) |
A typedef for pin handler functions. | |
Functions | |
int | Pins::getCanPinValue (uint8_t CAN_GPIO_Pin) |
Get the pin value of a predefined canbus pin. | |
int | Pins::getPinValue (uint8_t GPIO_Pin) |
Get the pin value of a predefined pin. | |
void | Pins::setPinValue (uint8_t GPIO_Pin, int value) |
Set the pin value of a predefined pin. | |
void | Pins::setInternalValue (uint8_t Internal_Pin, int value) |
Set the value of an internal pin. | |
void | Pins::resetPhysicalPins () |
Resets physical pins to their inital state. | |
void | Pins::update (void) |
Poll analog pin values. | |
void | Pins::stopCanPins (void) |
Stops background interrupts from sending canPins. | |
void | Pins::startCanPins (void) |
Starts background interrupts to send canPins, if any are to be sent. | |
void | Pins::initialize (void) |
Initialize all predefined pins. | |
void | Pins::debugPrint (void) |
Used for debugging. | |
Update, set, and get predefined pin values.
This module is used to simplify the usage of an ECU's GPIO pins.
Types
Through this module, each pin is predefined to be of a certain type.
These types include
Canbus
Every pin that is set as an input on one ECU can be received on another ECU over Canbus.
Sending pins over canbus is not limited to physical GPIO, virtual pins can also be created which are interacted with similarly to normal pins.
These pins, virtual or non virtual, that are sent over Canbus are referred to as CanPins.
Usage
Pins can either be read or set depending on whether they are input or output respectively.
Their actual values depend on whether they are pre-defined as an analog or digital pin, this is the same for CanPins.
Pins are normally interacted with by using Pins::getPinValue() and Pins::setPinValue().
CanPins can also be used through the same functions, however, it is recommend to explicitly call Pins::setInternalValue() and Pins::getCanPinValue() instead, as I have not actually tested the previous, and its just good practice I think.
Definition in file Pins.h.
#define PINS_ANALOG_HIGH (PINS_ANALOG_MAX - 1) |
#define PINS_ANALOG_MAX pwrtwo(PINS_ANALOG_RES) |
#define PINS_ANALOG_MIN 0 |
#define PINS_ANALOG_RES CONF_PINS_ANALOG_WRITE_RESOLUTION |
The current target bit resolution of the ECU, set by PinConfig.def.
#define PINS_VOLT_TO_ANALOG | ( | x | ) | (int)min(max((x / 5) * PINS_ANALOG_HIGH, PINS_ANALOG_MIN), PINS_ANALOG_HIGH) |