SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
Pins.h File Reference

Update, set, and get predefined pin values. More...

#include <stdint.h>
#include <stdlib.h>
#include "PPHelp.h"
#include "PinConfig.def"

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.
 

Detailed Description

Update, set, and get predefined pin values.

Author
IR
Version
0.1
Date
2020-11-11

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

  • Analog or Digital
  • Input or Output
Note
Pins with things like PWM or a DAC are used by default as the underlying gpio library does that.

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.

See also
PinConfig.def for more info on defining pin/canpin values and configuration of this module

Definition in file Pins.h.

Macro Definition Documentation

◆ PINS_ANALOG_HIGH

#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.

Definition at line 67 of file Pins.h.

◆ PINS_ANALOG_MAX

#define PINS_ANALOG_MAX   pwrtwo(PINS_ANALOG_RES)

The maximum analog value, given the current PINS_ANALOG_RES.

Definition at line 63 of file Pins.h.

◆ PINS_ANALOG_MIN

#define PINS_ANALOG_MIN   0

The minimum analog value. Its zero, I think it will always be zero. Not sure why i needed this.

Definition at line 71 of file Pins.h.

◆ PINS_ANALOG_RES

#define PINS_ANALOG_RES   CONF_PINS_ANALOG_WRITE_RESOLUTION

The current target bit resolution of the ECU, set by PinConfig.def.

Definition at line 59 of file Pins.h.

◆ PINS_VOLT_TO_ANALOG

#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.

Definition at line 76 of file Pins.h.