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.h
Go to the documentation of this file.
1
11#ifndef MAINMODULEV1_0_H
12#define MAINMODULEV1_0_H
13
14#include <Arduino.h>
15#include "CANTramModule.h"
16#include "CANTramCore.h"
17#include <PWMCore.h>
18#include "ESP32PWMCore.h"
19#include "OutputDefinition.h"
20#include "Debug.h"
21#include "ESP32_UART.h"
22#include "UARTInterface.h"
23#include "HardwareResource.h"
24#include "driver/adc.h"
25#include "soc/adc_channel.h"
26#include "esp_adc_cal.h"
27#include "Adafruit_MCP23X17.h"
28#include "ESP32_CANCore.h"
29#include "CANInterface.h"
30#include "ESP32_I2CCore.h"
31
33 public:
35 static const String HW_TYPE;
36 String getHWType() const override { return HW_TYPE; }
37 static const String HW_VERSION;
38 String getHWVersion() const override { return HW_VERSION; }
39 static const String FW_VERSION;
40 String getFWVersion() const override { return FW_VERSION; }
41 static constexpr uint8_t GPIO_DEMAND = 0;
42 uint8_t getGPIODemand() const override { return GPIO_DEMAND; }
43 static constexpr uint8_t GPIO_SUPPLY = 25;
44 uint8_t getGPIOSupply() const override { return GPIO_SUPPLY; }
45
46 // OutputProvider interface
47 bool configureOutput(OutputDefinition* def, OutputDefinition::ConfigurationMode mode) override;
49 bool setOutput(OutputDefinition* def, bool state) override;
50 bool getOutput(OutputDefinition* def) override;
51
52 //Shift register Pins
53 Adafruit_MCP23X17 shiftRegister;
54 //Chip IC7
55 static const uint8_t SR_PIN_0 = 0;
56 static const uint8_t SR_PIN_1 = 1;
57 static const uint8_t SR_PIN_2 = 2;
58 static const uint8_t SR_PIN_3 = 3;
59 static const uint8_t SR_PIN_4 = 4;
60 static const uint8_t SR_PIN_5 = 5;
61 static const uint8_t SR_PIN_6 = 6;
62 static const uint8_t SR_PIN_7 = 7;
63 static const uint8_t SR_PIN_8 = 8;
64 static const uint8_t SR_PIN_9 = 9;
65 static const uint8_t SR_PIN_10 = 10;
66 static const uint8_t SR_PIN_11 = 11;
67 static const uint8_t SR_PIN_12 = 12;
68 static const uint8_t SR_PIN_13 = 13;
69 static const uint8_t SR_PIN_14 = 14;
70 static const uint8_t SR_PIN_15 = 15;
71
72 OutputDefinition EXTEND[GPIO_SUPPLY] = {
73 // isShift, pinOrBit, adc, pwm, inputOnly, this, LOW
74 OutputDefinition(false, UART_RX, false, true, false, this), // 0
75 OutputDefinition(false, UART_TX, false, true, false, this), // 1
76 OutputDefinition(false, GPIO_NUM_32, false, true, false, this), // 2
77 OutputDefinition(false, GPIO_NUM_15, false, true, false, this), // 3
78 OutputDefinition(false, GPIO_NUM_33, false, true, false, this), // 4
79 OutputDefinition(false, GPIO_NUM_2, false, true, false, this), // 5
80 OutputDefinition(false, GPIO_NUM_25, false, true, false, this), // 6
81 OutputDefinition(false, GPIO_NUM_0, false, true, false, this), // 7
82 OutputDefinition(false, GPIO_NUM_26, false, true, false, this), // 8
83 OutputDefinition(false, GPIO_NUM_4, false, true, false, this), // 9
84 OutputDefinition(false, GPIO_NUM_27, false, true, false, this), // 10
85 OutputDefinition(false, GPIO_NUM_5, false, true, false, this), // 11
86 OutputDefinition(true, SR_PIN_15, false, false, false, this), // 12
87 OutputDefinition(true, SR_PIN_2, false, false, false, this), // 13
88 OutputDefinition(true, SR_PIN_14, false, false, false, this), // 14
89 OutputDefinition(true, SR_PIN_3, false, false, false, this), // 15
90 OutputDefinition(true, SR_PIN_13, false, false, false, this), // 16
91 OutputDefinition(true, SR_PIN_4, false, false, false, this), // 17
92 OutputDefinition(true, SR_PIN_12, false, false, false, this), // 18
93 OutputDefinition(true, SR_PIN_5, false, false, false, this), // 19
94 OutputDefinition(true, SR_PIN_11, false, false, false, this), // 20
95 OutputDefinition(true, SR_PIN_6, false, false, false, this), // 21
96 OutputDefinition(true, SR_PIN_10, false, false, false, this), // 22
97 OutputDefinition(true, SR_PIN_7, false, false, false, this), // 23
98 OutputDefinition(true, SR_PIN_9, false, false, false, this) // 24
99 };
100
101// Temperatur Pin
102static const uint8_t TEMP_PIN = GPIO_NUM_35; //using ADC1 on ESP32
103static const adc1_channel_t TEMP_ADC_CHANNEL = ADC1_GPIO35_CHANNEL; // GPIO35 is ADC1_CHANNEL_7
104static constexpr uint16_t TEMP_RES_1 = 6200; // Resistance at 25 degrees Celsius
105#ifdef MAINMODULE_TEMPERATURE_PROTOTYPE_BOARD //Use This buildflag, if you are using the temperaturesensor prototype board for testing
106#warning "Using temperature prototype board settings. This will result in wrong temperatures if you are using the mainmodule board."
107#warning "Make sure to clear the buildflag MAINMODULE_TEMPERATURE_PROTOTYPE_BOARD buildflag for production builds."
108static constexpr uint16_t TEMP_RES_2 = 12000; // Resistance at 25 degrees Celsius
109#else
110static constexpr uint16_t TEMP_RES_2 = 6200; // Resistance at 25 degrees Celsius
111#endif
112static constexpr float TEMP_FAKTOR = float(TEMP_RES_2)/float(TEMP_RES_1 + TEMP_RES_2); //Faktor for voltage divider
113static constexpr float TEMP_SUPPLY_VOLTAGE = 5000.0; // in millivolts
114static constexpr uint8_t TEMP_MULTISAMPLE = 16; //Number of samples to average
115static constexpr uint16_t ADC_MAX_VOLTAGE = 2450; //in millivolts
116esp_adc_cal_characteristics_t adc1_chars;
117static constexpr uint16_t ADC_DEFAULT_VREF = 1100;
118bool adc_calibrated;
119
120
121// CAN Pins
122ESP32_CANCore canCore;
123static const uint8_t CAN_TX = GPIO_NUM_17;
124static const uint8_t CAN_RX = GPIO_NUM_16;
125CANInterface canInterface;
126
127// SPI Pins
128static const uint8_t SPI_COPI = GPIO_NUM_21;
129static const uint8_t SPI_CIPO = GPIO_NUM_18;
130static const uint8_t SPI_SCK = GPIO_NUM_22;
131
132// I2C Pins
133static const uint8_t I2C_SDA = GPIO_NUM_13;
134static const uint8_t I2C_SCL = GPIO_NUM_14;
135
136// UART Pins
137static const uint8_t UART_TX = GPIO_NUM_19;
138static const uint8_t UART_RX = GPIO_NUM_23;
139
140// INT Pin
141static const uint8_t INT_PIN = GPIO_NUM_34;
142
143//Enable Pin
144static const uint8_t GENERAL_EN = SR_PIN_8;
145
146//LEDs
147static const uint8_t LED_WARNING = SR_PIN_0;
148static const uint8_t LED_ERROR = SR_PIN_1;
149
150//public funtions
151 bool reset()override;
152 bool attachModule(uint8_t slot,uint8_t gpioStart) override;
153
154 bool provideGPIOs() override;
155 bool requestGPIOs() override;
156 bool provideHardwareResources() override;
157 bool requestHardwareResources() override;
158 bool addInterfaces() override;
159 bool preInitialize() override;
160 bool initialize() override;
161
162 void enableOutputs(bool state) override;
163
164 uint16_t getTemperatureCelsius();
165
166
167 void cycle(uint8_t* response) override;
168
169 Interface** getInterfaces() override { return _interfaces; }
170 size_t getInterfaceCount() override { return INTERFACE_COUNT; }
171
172
173 bool setPWM(OutputDefinition* def, uint16_t value) override;
174 bool registerPWMChannel(OutputDefinition* def) override;
175 private:
176 static constexpr size_t INTERFACE_COUNT = 1; // Number of interfaces in the array
177 Interface* _interfaces[INTERFACE_COUNT]; // representation of the physical interfaces clamps
178 ESP32PWMCore _pwmCore;
179 ESP32_UART uart;
180 ESP32_I2CCore i2cCore;
181
182 static constexpr uint8_t UART_NUM = UART_NUM_1;
183 static constexpr uint16_t UART_BUFFER_SIZE = 1024;
184
185
186
187 bool startShiftRegister();
188 bool resetShiftRegister();
189
190 enum ShiftRegistertStatus{
191 NOT_STARTED,
192 STARTED,
193 FAILED
194 };
195
196 static constexpr uint8_t SHIFTREGISTER_I2C_ADDRESS = 0b100111;
197 static constexpr uint32_t SHIFTREGISTER_I2C_FREQUENCY = 400000; //400 kHz allowed frequency for MCP23X17
198 ShiftRegistertStatus _shiftregisterStatus = NOT_STARTED;
199
200 protected:
201 virtual UARTCore* getUartCore() override { return &uart; }
202
203};
204
205
206#endif
207
Declaration of the CANInterface class.
This class serves as the core manager for the CANTram modular system. It handles module attachment,...
Base class for CANTram hardware modules.
Logging and debug macro definitions for CANTramCore.
Declaration of the ESP32_CANCore class.
Base class for hardware resources.
Definitions for GPIO/output descriptors and provider interfaces.
Abstract PWM core interface for CANTram.
CANTramModule()=default
Default constructor.
Definition ESP32_I2CCore.h:13
Definition ESP32_UART.h:11
Definition ESP32PWMCore.h:8
Definition Interface.h:7
bool requestGPIOs() override
Request GPIOs from the core.
Definition MainModuleV1_0.cpp:75
bool initialize() override
Initialize the module and its hardware subsystems.
Definition MainModuleV1_0.cpp:176
bool registerPWMChannel(OutputDefinition *def) override
Register a PWM channel for an output.
Definition MainModuleV1_0.cpp:392
void enableOutputs(bool state) override
Enable or disable all outputs managed by this provider.
Definition MainModuleV1_0_outputs.cpp:242
bool reset() override
Reset the module and its hardware cores.
Definition MainModuleV1_0.cpp:23
bool preInitialize() override
Pre-initialize the module after attachment.
Definition MainModuleV1_0.cpp:128
void cycle(uint8_t *response) override
Periodic cycle callback for the module.
Definition MainModuleV1_0.cpp:351
bool requestHardwareResources() override
Request hardware resources from the core.
Definition MainModuleV1_0.cpp:102
uint8_t getGPIODemand() const override
Get the GPIO demand of the module.
Definition MainModuleV1_0.h:42
bool attachModule(uint8_t slot, uint8_t gpioStart) override
Attach this module to a slot and GPIO start index.
Definition MainModuleV1_0.cpp:44
size_t getInterfaceCount() override
Get number of interfaces provided by the module.
Definition MainModuleV1_0.h:170
uint8_t getGPIOSupply() const override
Get the GPIO supply capacity of the module.
Definition MainModuleV1_0.h:44
bool addInterfaces() override
Register any interfaces provided by this module.
Definition MainModuleV1_0.cpp:113
bool getOutput(OutputDefinition *def) override
Get the current state of a digital output.
Definition MainModuleV1_0_outputs.cpp:147
bool provideGPIOs() override
Provide GPIO output definitions to CANTramCore.
Definition MainModuleV1_0.cpp:56
String getFWVersion() const override
Get the firmware version string.
Definition MainModuleV1_0.h:40
bool configureOutput(OutputDefinition *def, OutputDefinition::ConfigurationMode mode) override
Configure an output's direction/mode.
Definition MainModuleV1_0_outputs.cpp:44
uint16_t getTemperatureCelsius()
Get the temperature in Celsius in 0.1°C steps.
Definition MainModuleV1_0.cpp:410
String getHWVersion() const override
Get the hardware version string.
Definition MainModuleV1_0.h:38
bool provideHardwareResources() override
Provide hardware resources (UART, PWM, etc.) to CANTramCore.
Definition MainModuleV1_0.cpp:84
bool setPWM(OutputDefinition *def, uint16_t value) override
Set PWM duty for an output definition.
Definition MainModuleV1_0.cpp:370
String getHWType() const override
Get the hardware type string.
Definition MainModuleV1_0.h:36
Interface ** getInterfaces() override
Get pointer to module's interface array.
Definition MainModuleV1_0.h:169
bool setOutput(OutputDefinition *def, bool state) override
Set the logic level on a pin of the module.
Definition MainModuleV1_0_outputs.cpp:97
MainModuleV1_0()
Construct a new MainModuleV1_0::MainModuleV1_0 object.
Definition MainModuleV1_0_outputs.cpp:28
virtual UARTCore * getUartCore() override
Obtain a pointer to an available UARTCore.
Definition MainModuleV1_0.h:201
Describes an available output (GPIO or shift register bit).
Definition OutputDefinition.h:24
Extended output provider interface for PWM-capable outputs.
Definition OutputDefinition.h:148
Base class for platform-specific UART implementations.
Definition UARTCore.h:22
Abstract interface for objects that supply a UARTCore instance.
Definition UARTCore.h:175