CANTram Framework 1.0.1
Dieses Framework ermöglicht die Nutzung der CANTram Hardware, einer Mikrocontroller basierten mdoularen Steuerung.
Loading...
Searching...
No Matches
MainModuleV1_0 Class Reference
Inheritance diagram for MainModuleV1_0:
Collaboration diagram for MainModuleV1_0:

Public Member Functions

 MainModuleV1_0 ()
 Construct a new MainModuleV1_0::MainModuleV1_0 object.
String getHWType () const override
 Get the hardware type string.
String getHWVersion () const override
 Get the hardware version string.
String getFWVersion () const override
 Get the firmware version string.
uint8_t getGPIODemand () const override
 Get the GPIO demand of the module.
uint8_t getGPIOSupply () const override
 Get the GPIO supply capacity of the module.
bool configureOutput (OutputDefinition *def, OutputDefinition::ConfigurationMode mode) override
 Configure an output's direction/mode.
bool configureOutput (OutputDefinition *def)
 Configures the output for a specific pin or bit.
bool setOutput (OutputDefinition *def, bool state) override
 Set the logic level on a pin of the module.
bool getOutput (OutputDefinition *def) override
 Get the current state of a digital output.
bool reset () override
 Reset the module and its hardware cores.
bool attachModule (uint8_t slot, uint8_t gpioStart) override
 Attach this module to a slot and GPIO start index.
bool provideGPIOs () override
 Provide GPIO output definitions to CANTramCore.
bool requestGPIOs () override
 Request GPIOs from the core.
bool provideHardwareResources () override
 Provide hardware resources (UART, PWM, etc.) to CANTramCore.
bool requestHardwareResources () override
 Request hardware resources from the core.
bool addInterfaces () override
 Register any interfaces provided by this module.
bool preInitialize () override
 Pre-initialize the module after attachment.
bool initialize () override
 Initialize the module and its hardware subsystems.
void enableOutputs (bool state) override
 Enable or disable all outputs managed by this provider.
uint16_t getTemperatureCelsius ()
 Get the temperature in Celsius in 0.1°C steps.
void cycle (uint8_t *response) override
 Periodic cycle callback for the module.
Interface ** getInterfaces () override
 Get pointer to module's interface array.
size_t getInterfaceCount () override
 Get number of interfaces provided by the module.
bool setPWM (OutputDefinition *def, uint16_t value) override
 Set PWM duty for an output definition.
bool registerPWMChannel (OutputDefinition *def) override
 Register a PWM channel for an output.
Public Member Functions inherited from CANTramModule
 CANTramModule ()=default
 Default constructor.
virtual ~CANTramModule ()=default
 Destructor.
uint8_t getSlot () const
 Get assigned slot index.
uint8_t getGPIOStart () const
 Get starting GPIO index assigned to the module.
Public Member Functions inherited from OutputProvider
virtual void disableOutputs ()
 Disable all outputs managed by this provider.

Public Attributes

Adafruit_MCP23X17 shiftRegister
OutputDefinition EXTEND [GPIO_SUPPLY]
esp_adc_cal_characteristics_t adc1_chars
bool adc_calibrated
ESP32_CANCore canCore
CANInterface canInterface

Static Public Attributes

static const String HW_TYPE = "MainModuleV1.0"
static const String HW_VERSION = "1.0"
static const String FW_VERSION = "1.0"
static constexpr uint8_t GPIO_DEMAND = 0
static constexpr uint8_t GPIO_SUPPLY = 25
static const uint8_t SR_PIN_0 = 0
static const uint8_t SR_PIN_1 = 1
static const uint8_t SR_PIN_2 = 2
static const uint8_t SR_PIN_3 = 3
static const uint8_t SR_PIN_4 = 4
static const uint8_t SR_PIN_5 = 5
static const uint8_t SR_PIN_6 = 6
static const uint8_t SR_PIN_7 = 7
static const uint8_t SR_PIN_8 = 8
static const uint8_t SR_PIN_9 = 9
static const uint8_t SR_PIN_10 = 10
static const uint8_t SR_PIN_11 = 11
static const uint8_t SR_PIN_12 = 12
static const uint8_t SR_PIN_13 = 13
static const uint8_t SR_PIN_14 = 14
static const uint8_t SR_PIN_15 = 15
static const uint8_t TEMP_PIN = GPIO_NUM_35
static const adc1_channel_t TEMP_ADC_CHANNEL = ADC1_GPIO35_CHANNEL
static constexpr uint16_t TEMP_RES_1 = 6200
static constexpr uint16_t TEMP_RES_2 = 6200
static constexpr float TEMP_FAKTOR = float(TEMP_RES_2)/float(TEMP_RES_1 + TEMP_RES_2)
static constexpr float TEMP_SUPPLY_VOLTAGE = 5000.0
static constexpr uint8_t TEMP_MULTISAMPLE = 16
static constexpr uint16_t ADC_MAX_VOLTAGE = 2450
static constexpr uint16_t ADC_DEFAULT_VREF = 1100
static const uint8_t CAN_TX = GPIO_NUM_17
static const uint8_t CAN_RX = GPIO_NUM_16
static const uint8_t SPI_COPI = GPIO_NUM_21
static const uint8_t SPI_CIPO = GPIO_NUM_18
static const uint8_t SPI_SCK = GPIO_NUM_22
static const uint8_t I2C_SDA = GPIO_NUM_13
static const uint8_t I2C_SCL = GPIO_NUM_14
static const uint8_t UART_TX = GPIO_NUM_19
static const uint8_t UART_RX = GPIO_NUM_23
static const uint8_t INT_PIN = GPIO_NUM_34
static const uint8_t GENERAL_EN = SR_PIN_8
static const uint8_t LED_WARNING = SR_PIN_0
static const uint8_t LED_ERROR = SR_PIN_1

Protected Member Functions

virtual UARTCore * getUartCore () override
 Obtain a pointer to an available UARTCore.

Additional Inherited Members

Protected Attributes inherited from CANTramModule
uint8_t SLOT = 0
uint8_t GPIO_START = 0

Constructor & Destructor Documentation

◆ MainModuleV1_0()

MainModuleV1_0::MainModuleV1_0 ( )

Construct a new MainModuleV1_0::MainModuleV1_0 object.

This constructor explicitly calls the ESP32_I2CCore constructor with I2C bus 0 so Wire instead of Wire1 is used.

Member Function Documentation

◆ addInterfaces()

bool MainModuleV1_0::addInterfaces ( )
overridevirtual

Register any interfaces provided by this module.

Add interface instances to the module so the core can enumerate and use them.

Returns
true if interfaces were added successfully, false otherwise.

Implements CANTramModule.

◆ attachModule()

bool MainModuleV1_0::attachModule ( uint8_t slot,
uint8_t gpioStart )
overridevirtual

Attach this module to a slot and GPIO start index.

Calls the base CANTramModule attach implementation and performs any module-specific attach logic.

Parameters
slotSlot index to attach the module to.
gpioStartStarting GPIO index assigned to this module.
Returns
true if the attach operation was successful, false otherwise.

Reimplemented from CANTramModule.

Here is the call graph for this function:

◆ configureOutput() [1/2]

bool MainModuleV1_0::configureOutput ( OutputDefinition * def)

Configures the output for a specific pin or bit.

Parameters
defGPIO number or shiftRegister output ID of desired output
mode(Optional) Specify the direction of the pin. Default is OUTPUT
Returns
true, if the cofiguration was completed successfully
false, if error were encountered during the configuration. See output log for more details
Here is the call graph for this function:

◆ configureOutput() [2/2]

bool MainModuleV1_0::configureOutput ( OutputDefinition * def,
OutputDefinition::ConfigurationMode mode )
overridevirtual

Configure an output's direction/mode.

Configure the physical output referenced by def to the given mode (e.g., INPUT, OUTPUT).

Parameters
defPointer to the OutputDefinition describing the output to configure.
modeMode value to set (Arduino-style constants like INPUT/OUTPUT).
Returns
true if configuration succeeded, false on error.

Implements OutputProvider.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycle()

void MainModuleV1_0::cycle ( uint8_t * response)
overridevirtual

Periodic cycle callback for the module.

Called by the core to perform periodic tasks. Implement module-specific cyclic behavior here.

Parameters
responsePointer to a response buffer where the module may write response bytes. May be nullptr if not used.

Reimplemented from CANTramModule.

Here is the call graph for this function:

◆ enableOutputs()

void MainModuleV1_0::enableOutputs ( bool state)
overridevirtual

Enable or disable all outputs managed by this provider.

Globally enable or disable outputs. Implementation-specific behavior (e.g., power gating). This method is called by the CANTramCore during initialization.

Parameters
statetrue to enable outputs, false to disable.

Reimplemented from OutputProvider.

Here is the call graph for this function:

◆ getFWVersion()

String MainModuleV1_0::getFWVersion ( ) const
inlineoverridevirtual

Get the firmware version string.

Returns the firmware version string implemented by the module.

Returns
String Firmware version (e.g. "1.0").

Implements CANTramModule.

◆ getGPIODemand()

uint8_t MainModuleV1_0::getGPIODemand ( ) const
inlineoverridevirtual

Get the GPIO demand of the module.

Returns how many GPIOs this module requires from the core.

Returns
uint8_t Number of GPIOs demanded by the module.

Implements CANTramModule.

◆ getGPIOSupply()

uint8_t MainModuleV1_0::getGPIOSupply ( ) const
inlineoverridevirtual

Get the GPIO supply capacity of the module.

Returns how many GPIOs this module provides/supplies to the system.

Returns
uint8_t Number of GPIOs supplied by the module.

Implements CANTramModule.

◆ getHWType()

String MainModuleV1_0::getHWType ( ) const
inlineoverridevirtual

Get the hardware type string.

Returns a human readable hardware type identifier for the concrete module implementation.

Returns
String Hardware type identifier (e.g. "MainModuleV1.0").

Implements CANTramModule.

◆ getHWVersion()

String MainModuleV1_0::getHWVersion ( ) const
inlineoverridevirtual

Get the hardware version string.

Returns the hardware revision/version string for the module.

Returns
String Hardware version (e.g. "1.0").

Implements CANTramModule.

◆ getInterfaceCount()

size_t MainModuleV1_0::getInterfaceCount ( )
inlineoverridevirtual

Get number of interfaces provided by the module.

Return the number of entries in the interfaces array returned by getInterfaces().

Returns
size_t Number of interface pointers.

Implements CANTramModule.

◆ getInterfaces()

Interface ** MainModuleV1_0::getInterfaces ( )
inlineoverridevirtual

Get pointer to module's interface array.

Returns a pointer to the internal Interface* array used by the core to enumerate interfaces.

Returns
Interface** Pointer to the first element of the module's interfaces array.

Implements CANTramModule.

◆ getOutput()

bool MainModuleV1_0::getOutput ( OutputDefinition * def)
overridevirtual

Get the current state of a digital output.

Parameters
defOutput definition containing the pin information
Returns
true if the output state was retrieved successfully
false if an error occurred

Implements OutputProvider.

Here is the call graph for this function:

◆ getTemperatureCelsius()

uint16_t MainModuleV1_0::getTemperatureCelsius ( )

Get the temperature in Celsius in 0.1°C steps.

Reads ADC samples (digital controller on C3, single reads on ESP32) and converts them to temperature using calibration or approximation. Returns temperature in tenths of a degree Celsius (e.g., 253 means 25.3°C).

Returns
int16_t Temperature in 0.1°C steps.
Here is the caller graph for this function:

◆ getUartCore()

virtual UARTCore * MainModuleV1_0::getUartCore ( )
inlineoverrideprotectedvirtual

Obtain a pointer to an available UARTCore.

Returns a pointer to a UARTCore instance that can be used by clients. May return nullptr if no UARTCore is available.

Returns
UARTCore* Pointer to a UARTCore instance or nullptr if none available.

Implements UARTProvider.

◆ initialize()

bool MainModuleV1_0::initialize ( )
overridevirtual

Initialize the module and its hardware subsystems.

Initializes UART, PWM, I2C, SPI and ADC subsystems as required by the module. This prepares the module for operation after attachment and resource provisioning.

Returns
true if all initialization steps succeeded, false if any step failed.

Initialize the shift register for GPIO expansion.

Configuration of shift register must happen before initialization of the core!

Otherwise errors will be generated since the core is not able to set the initial values of these outputs

Returns
true if initialization succeeded, false otherwise.

Implements CANTramModule.

◆ preInitialize()

bool MainModuleV1_0::preInitialize ( )
overridevirtual

Pre-initialize the module after attachment.

Initializes I2C core before main intialization, because the shiftregister needs to be started to set the gpios of the extend bus.

Returns
true if pre-initialization succeeded, false otherwise.

Reimplemented from CANTramModule.

Here is the call graph for this function:

◆ provideGPIOs()

bool MainModuleV1_0::provideGPIOs ( )
overridevirtual

Provide GPIO output definitions to CANTramCore.

Registers the module's output definition table with CANTramCore so the core can manage GPIO provisioning for this module.

Returns
true if output definitions were added successfully, false otherwise.

Implements CANTramModule.

Here is the call graph for this function:

◆ provideHardwareResources()

bool MainModuleV1_0::provideHardwareResources ( )
overridevirtual

Provide hardware resources (UART, PWM, etc.) to CANTramCore.

Attaches hardware resource instances to the core so other modules may request/use them.

Returns
true if all resources were attached successfully, false otherwise.

Implements CANTramModule.

Here is the call graph for this function:

◆ registerPWMChannel()

bool MainModuleV1_0::registerPWMChannel ( OutputDefinition * def)
overridevirtual

Register a PWM channel for an output.

Initializes PWM core and requests a channel allocation for the given output definition.

Parameters
defPointer to the OutputDefinition to register for PWM.
Returns
true if channel registration succeeded, false otherwise.

Implements PWMOutputProvider.

Here is the call graph for this function:

◆ requestGPIOs()

bool MainModuleV1_0::requestGPIOs ( )
overridevirtual

Request GPIOs from the core.

Called by the core when module GPIOs should be configured/allocated. Module should request any runtime GPIOs here.

Returns
true if requests succeeded, false otherwise.

Implements CANTramModule.

◆ requestHardwareResources()

bool MainModuleV1_0::requestHardwareResources ( )
overridevirtual

Request hardware resources from the core.

Called when the module should request any hardware resources it needs. Implement module-specific requests here.

Returns
true if all resource requests were granted, false otherwise.

Implements CANTramModule.

◆ reset()

bool MainModuleV1_0::reset ( )
overridevirtual

Reset the module and its hardware cores.

Calls reset on UART and PWM cores and resets the shift register to return the module to a known default state.

Returns
true if all resets succeeded, false if any reset failed.

Reimplemented from CANTramModule.

◆ setOutput()

bool MainModuleV1_0::setOutput ( OutputDefinition * def,
bool state )
overridevirtual

Set the logic level on a pin of the module.

Parameters
defOutput to set the state
statelogic level HIGH or LOW
Returns
true, if logic level was set correctly

Implements OutputProvider.

Here is the call graph for this function:

◆ setPWM()

bool MainModuleV1_0::setPWM ( OutputDefinition * def,
uint16_t value )
overridevirtual

Set PWM duty for an output definition.

Validates the output definition for PWM capability and delegates to the PWM core to set the duty cycle.

Parameters
defPointer to the OutputDefinition describing the output.
valueDuty value to set (implementation-specific range).
Returns
true if PWM was set successfully, false on error (e.g., non-PWM output).

Implements PWMOutputProvider.

Here is the call graph for this function:

Member Data Documentation

◆ EXTEND

OutputDefinition MainModuleV1_0::EXTEND[GPIO_SUPPLY]
Initial value:
= {
OutputDefinition(false, UART_RX, false, true, false, this),
OutputDefinition(false, UART_TX, false, true, false, this),
OutputDefinition(false, GPIO_NUM_32, false, true, false, this),
OutputDefinition(false, GPIO_NUM_15, false, true, false, this),
OutputDefinition(false, GPIO_NUM_33, false, true, false, this),
OutputDefinition(false, GPIO_NUM_2, false, true, false, this),
OutputDefinition(false, GPIO_NUM_25, false, true, false, this),
OutputDefinition(false, GPIO_NUM_0, false, true, false, this),
OutputDefinition(false, GPIO_NUM_26, false, true, false, this),
OutputDefinition(false, GPIO_NUM_4, false, true, false, this),
OutputDefinition(false, GPIO_NUM_27, false, true, false, this),
OutputDefinition(false, GPIO_NUM_5, false, true, false, this),
OutputDefinition(true, SR_PIN_15, false, false, false, this),
OutputDefinition(true, SR_PIN_2, false, false, false, this),
OutputDefinition(true, SR_PIN_14, false, false, false, this),
OutputDefinition(true, SR_PIN_3, false, false, false, this),
OutputDefinition(true, SR_PIN_13, false, false, false, this),
OutputDefinition(true, SR_PIN_4, false, false, false, this),
OutputDefinition(true, SR_PIN_12, false, false, false, this),
OutputDefinition(true, SR_PIN_5, false, false, false, this),
OutputDefinition(true, SR_PIN_11, false, false, false, this),
OutputDefinition(true, SR_PIN_6, false, false, false, this),
OutputDefinition(true, SR_PIN_10, false, false, false, this),
OutputDefinition(true, SR_PIN_7, false, false, false, this),
OutputDefinition(true, SR_PIN_9, false, false, false, this)
}
Describes an available output (GPIO or shift register bit).
Definition OutputDefinition.h:24

The documentation for this class was generated from the following files:
  • C:/Users/leowa/Documents/PlatformIO/Projects/CANTramFrameworkUsage/lib/CANTramFramework/include/MainModuleV1_0.h
  • C:/Users/leowa/Documents/PlatformIO/Projects/CANTramFrameworkUsage/lib/CANTramFramework/src/modules/MainModuleV1_0.cpp
  • C:/Users/leowa/Documents/PlatformIO/Projects/CANTramFrameworkUsage/lib/CANTramFramework/src/modules/MainModuleV1_0_outputs.cpp