Skip to content

Feature: GPIO remapping for alternative OVMS modules #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions vehicle/OVMS.V3/components/gpio_maps/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
GPIO Definitions for alternative OVMS Hardware
==============================================
The default GPIO assignments are defined in `ovm_peripherals.h`.
By switching to an alternative GPIO mapping via `make menuconfig -> Component config -> Open Vehicle Monitoring System -> Hardware Support -> Choose GPIO Mapping`, non default hardware can utilize the OVMS firmware.

Requirements
------------
- the hardware components are compatible with the default OVMS module, e.g. ESP32, Simcom modem, ESP32Can and MCP2515 based CAN bus
- the names of the pins are consistent with the firmware (see below for details)
- all hardware components need to be selected via `make menuconfig`

GPIO Names and Functions
------------------------

| Name | Function |
| ---------------------- | ------------------------------------------------------ |
| VSPI_PIN_MISO | SPI input pin of ESP32 (master) - connects to MCP2515 chips |
| VSPI_PIN_MOSI | SPI output pin of ESP32 (master) |
| VSPI_PIN_CLK | SPI clock pin of ESP32 |
| VSPI_PIN_MCP2515_1_CS | chip select of first MCP2515 |
| VSPI_PIN_MCP2515_1_INT | interrupt of first MCP2515 |
| VSPI_PIN_MCP2515_2_CS | chip select of second MCP2515 |
| VSPI_PIN_MCP2515_2_INT | interrupt of second MCP2515 |
| ESP32CAN_PIN_TX | transmit pin of ESP32 built-in CAN bus |
| ESP32CAN_PIN_RX | receive pin of ESP32 built-in CAN bus |
| MAX7317_CAN1_EN | RS pin of CAN transceiver of CAN 1 via GPIO extender |
| ESP32CAN_PIN_RS | RS pin of CAN transceiver of ESP32 built-in CAN bus (non standard Hardware) |
| VSPI_PIN_MCP2515_SWCAN_CS | chip select of third MCP2515 vio GPIO extender |
| VSPI_PIN_MCP2515_SWCAN_INT | interrupt of third MCP2515 via GPIO extender |
| MODEM_GPIO_RX | UART RX pin connected to modem |
| MODEM_GPIO_TX | UART TX pin connected to modem |
| MODEM_GPIO_DTR | UART DTR pin connected to modem |
| MODEM_EGPIO_DTR | UART DTR pin connected to modem via GPIO extender |
| MAX7317_MDM_DTR | UART DTR pin connected to modem via GPIO extender |
| MODEM_GPIO_RING | UART RING pin connected to modem |
| MODEM_GPIO_RESET | modem reset pin |
| MODEM_GPIO_PWR | modem power (inverted logic) |
| MODEM_EGPIO_PWR | modem power (inverted logic) via GPIO extender |
| MAX7317_MDM_EN | modem power (inverted logic) via GPIO extender (same as EGPIO_PWR) |
| SDCARD_PIN_CLK | SDMMC clock pin |
| SDCARD_PIN_CMD | SDMMC CMD pin |
| SDCARD_PIN_D0 | SDMMC data 0 pin |
| SDCARD_PIN_CD | SDMMC Card detect pin |
| MAX7317_SW_CTL | EXT_12V power switch |
| MAX7317_EGPIO_1 | GPIO extender pin |
| MAX7317_EGPIO_2 | GPIO extender pin |
| MAX7317_EGPIO_3 | GPIO extender pin |
| MAX7317_EGPIO_4 | GPIO extender pin |
| MAX7317_EGPIO_5 | GPIO extender pin |
| MAX7317_EGPIO_6 | GPIO extender pin |
| MAX7317_EGPIO_7 | GPIO extender pin |
| MAX7317_EGPIO_8 | GPIO extender pin |
| MAX7317_SWCAN_MODE0 | Fourth CAN bus pin |
| MAX7317_SWCAN_MODE1 | Fourth CAN bus pin |
| MAX7317_SWCAN_STATUS_LED | Fourth CAN bus status LED |
| MAX7317_SWCAN_TX_LED | Fourth CAN bus TX LED |
| MAX7317_SWCAN_RX_LED | Fourth CAN bus RX LED |


Some Remarks
------------

- The RS pin of the CAN transceiver SN65HVD233 or similar, allows to switch between a listen only mode (high level) and standard mode (low level)
- The RS pin is only directly connected to a GPIO for the built-in ESP32CAN bus.
- The RS pin of the other CAN buses is driven by the IO pins of the MCP2515 CAN bus controller (via SPI commands)
- All names containing `MAX7317` or `EGPIO` are only required, if the GPIO extender chip MAX7317 is present and activated via `menuconfig`
- Exception: `MODEM_EGPIO_PWR` and `MODEM_EGPIO_DTR` have to be set even if NO GPIO extender is present. Set to the same value as `MODEM_GPIO_PWR` and `MODEM_GPIO_DTR` respectively.
- The modem power pin: Simcom recommends to utilize an open collector driver (NPN transistor) for the PWR pin. This is present in the default OVMS module. The logic is therefore inverted in the Simcom modem drivers.
- The Chip Select and Interrupt pins have to be defined for CAN bus 1-3, even, if not all CAN buses are present. Not existing signals can be set `-1` e.g. `#define VSPI_PIN_MCP2515_2_INT -1`. This avoids compilation problems, but will cause an error message due to an invalid GPIO pin number.

How to create a GPIO Mapping file
---------------------------------
- Create a file in `components/gpio_maps` e.g `mygpios.h`
- Assign the GPIO pins to the corresponding name via `#define` statements.
- Enter the new file name via `menuconfig` as the GPIO map. If a different directory is chosen for the location of the map, the full path has to be specified.

Example snippet
---------------

````
#define VSPI_PIN_MISO 19
#define VSPI_PIN_MOSI 23
#define VSPI_PIN_CLK 18

````

Be aware, that the numbers are the GPIO numbers and NOT the ESP32 pin numbers.


6 changes: 6 additions & 0 deletions vehicle/OVMS.V3/components/gpio_maps/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Main Makefile. This is basically the same as a component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

COMPONENT_ADD_INCLUDEDIRS := .
37 changes: 37 additions & 0 deletions vehicle/OVMS.V3/components/gpio_maps/lilygo_tc_v10.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// GPIO Map for Lilygo T-Call A7670E V 1.0 on rev B motherboard
//

#define VSPI_PIN_MISO 19
#define VSPI_PIN_MOSI 23
#define VSPI_PIN_CLK 18

// GPIO pin mapping for Lilygo T-Call A7670 V1.0 and V1.1 (modem interface)
// Function | V1.0 | V1.1
// -----------+----------+----------
// Modem TX | 26 | 27
// Modem RX | 25 | 26
// Modem DTR | 14 | 32
// Modem RING | 13 | 33
// Modem PWR | 4 | 4
// Modem RESET| 27 | 5

#define ESP32CAN_PIN_TX 2
#define ESP32CAN_PIN_RX 34
#define ESP32CAN_PIN_RS 21 // RS pin of CAN transceiver

#define MODEM_GPIO_RX 25
#define MODEM_GPIO_TX 26
#define MODEM_GPIO_DTR 14
#define MODEM_GPIO_RING 13 // NOT USED
#define MODEM_GPIO_RESET 27 // NOT YET USED (active low)

// common for V1.0 and V1.1 and Rev A and B
#define MODEM_GPIO_PWR 4 // switch POWERKEY of Modem (active high)
#define VSPI_PIN_MCP2515_1_CS 22
#define VSPI_PIN_MCP2515_1_INT 35
// #define ADC_CHANNEL_12V 0 // Measure OBD 12V - GPIO36/SENSOR_VP
#define MODEM_EGPIO_PWR MODEM_GPIO_PWR // avoid problem with modem intialization
#define MODEM_EGPIO_DTR MODEM_GPIO_DTR
#define VSPI_PIN_MCP2515_2_INT -1 // dummy definition to avoid compiler error
#define VSPI_PIN_MCP2515_2_CS -1
36 changes: 36 additions & 0 deletions vehicle/OVMS.V3/components/gpio_maps/lilygo_tc_v10_a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// GPIO Map for Lilygo T-Call A7670E V 1.0 on rev A motherboard
//

#define VSPI_PIN_MISO 19
#define VSPI_PIN_MOSI 23
#define VSPI_PIN_CLK 18

// GPIO pin mapping for Lilygo T-Call A7670 V1.0 and V1.1 (modem interface)
// Function | V1.0 | V1.1
// -----------+----------+----------
// Modem TX | 26 | 27
// Modem RX | 25 | 26
// Modem DTR | 14 | 32
// Modem RING | 13 | 33
// Modem PWR | 4 | 4
// Modem RESET| 27 | 5

#define ESP32CAN_PIN_TX 32
#define ESP32CAN_PIN_RX 34
#define ESP32CAN_PIN_RS 33 // RS pin of CAN transceiver

#define MODEM_GPIO_RX 25
#define MODEM_GPIO_TX 26
#define MODEM_GPIO_DTR 14
#define MODEM_GPIO_RING 13 // NOT USED
#define MODEM_GPIO_RESET 27 // NOT YET USED (active low)

#define MODEM_GPIO_PWR 4 // switch POWERKEY of Modem (active high)
#define VSPI_PIN_MCP2515_1_CS 22
#define VSPI_PIN_MCP2515_1_INT 35
// #define ADC_CHANNEL_12V 0 // Measure OBD 12V - GPIO36/SENSOR_VP
#define MODEM_EGPIO_PWR MODEM_GPIO_PWR // avoid problem with modem intialization
#define MODEM_EGPIO_DTR MODEM_GPIO_DTR
#define VSPI_PIN_MCP2515_2_INT -1 // dummy definition to avoid compiler error
#define VSPI_PIN_MCP2515_2_CS -1
37 changes: 37 additions & 0 deletions vehicle/OVMS.V3/components/gpio_maps/lilygo_tc_v11.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// GPIO Map for Lilygo T-Call A7670E V 1.1 on rev B motherboard
//

#define VSPI_PIN_MISO 19
#define VSPI_PIN_MOSI 23
#define VSPI_PIN_CLK 18

// GPIO pin mapping for Lilygo T-Call A7670 V1.0 and V1.1 (modem interface)
// Function | V1.0 | V1.1
// -----------+----------+----------
// Modem TX | 26 | 27
// Modem RX | 25 | 26
// Modem DTR | 14 | 32
// Modem RING | 13 | 33
// Modem PWR | 4 | 4
// Modem RESET| 27 | 5

#define ESP32CAN_PIN_TX 2
#define ESP32CAN_PIN_RX 34
#define ESP32CAN_PIN_RS 21 // RS pin of CAN transceiver

#define MODEM_GPIO_RX 26
#define MODEM_GPIO_TX 27
#define MODEM_GPIO_DTR 32
#define MODEM_GPIO_RING 33 // NOT USED
#define MODEM_GPIO_RESET 5 // NOT YET USED (active low)

// common for V1.0 and V1.1 and Rev A and B
#define MODEM_GPIO_PWR 4 // switch POWERKEY of Modem (active high)
#define VSPI_PIN_MCP2515_1_CS 22
#define VSPI_PIN_MCP2515_1_INT 35
// #define ADC_CHANNEL_12V 0 // Measure OBD 12V - GPIO36/SENSOR_VP
#define MODEM_EGPIO_PWR MODEM_GPIO_PWR // avoid problem with modem intialization
#define MODEM_EGPIO_DTR MODEM_GPIO_DTR
#define VSPI_PIN_MCP2515_2_INT -1 // dummy definition to avoid compiler error
#define VSPI_PIN_MCP2515_2_CS -1
31 changes: 29 additions & 2 deletions vehicle/OVMS.V3/main/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,39 @@ config OVMS_HW_BASE_3_1
help
Select this: OVMS base production hardware v3.1


endchoice # OVMS_HW_MODEL

choice OVMS_HW_SELECT_GPIO_MAP
prompt "Choose GPIO Mapping "
default OVMS_HW_DEFAULT_GPIO_MAP
help
OVMS_HW_DEFAULT_GPIO_MAP Default GPIO assignment of OVMS module
OVMS_HW_REMAP_GPIO Alternative GPIO mapping

config OVMS_HW_DEFAULT_GPIO_MAP
bool "Default OVMS module GPIO Mapping"
help
Select this for the default OVMS module

config OVMS_HW_REMAP_GPIO
bool "Enable alternative OVMS modules/GPIO Mapping"
help
Select this: Enable alternative mapping of ESP32 GPIOs

endchoice # OVMS_HW_SELECT_GPIO_MAP

config OVMS_GPIO_MAP_FILE
string "File with GPIO mapping: "
default NONE
depends on OVMS_HW_REMAP_GPIO
help
The GPIO mapping will be included in ovms_peripheral from the selected file

config OVMS_HW_SPIMEM_AGGRESSIVE
bool "Aggressively use SPI RAM (rather than internal RAM)"
default y
depends on OVMS && OVMS_HW_BASE_3_1
depends on OVMS && OVMS_HW_BASE_3_1
help
Enable to aggressively allocate from SPI RAM (rather than internal RAM).

Expand Down Expand Up @@ -822,7 +849,7 @@ config OVMS_COMP_CELLULAR
config OVMS_COMP_CELLULAR_SIMCOM
bool "Include support for SIMCOM cellular modems"
default y
depends on OVMS && OVMS_COMP_MAX7317 && OVMS_COMP_CELLULAR
depends on OVMS && OVMS_COMP_CELLULAR && ( OVMS_COMP_MAX7317 || OVMS_HW_REMAP_GPIO )
help
Enable to include support for SIMCOM cellular modems

Expand Down
19 changes: 19 additions & 0 deletions vehicle/OVMS.V3/main/ovms_peripherals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ Peripherals::Peripherals()
gpio_set_pull_mode((gpio_num_t)SDCARD_PIN_D0, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
#endif // #ifdef CONFIG_OVMS_COMP_SDCARD

#ifdef CONFIG_OVMS_HW_REMAP_GPIO
#ifdef MODEM_GPIO_PWR
gpio_set_direction((gpio_num_t)MODEM_GPIO_PWR, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)MODEM_GPIO_PWR, 0); // signal is inverted by NPN transistor - set to high
#endif
#ifdef MODEM_GPIO_RESET
gpio_set_direction((gpio_num_t)MODEM_GPIO_RESET, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)MODEM_GPIO_RESET,1); // active LOW - NOT USED YET
#endif
#ifdef MODEM_GPIO_RING
gpio_set_direction((gpio_num_t)MODEM_GPIO_RING, GPIO_MODE_INPUT);
#endif
#ifdef MODEM_GPIO_DTR
gpio_set_direction((gpio_num_t)MODEM_GPIO_DTR, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)MODEM_GPIO_DTR, 1);
#endif
#endif // #ifdef CONFIG_OVMS_HW_REMAP_GPIO


ESP_LOGI(TAG, " ESP32 system");
m_esp32 = new esp32system("esp32");

Expand Down
12 changes: 12 additions & 0 deletions vehicle/OVMS.V3/main/ovms_peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@
#include "ext12v.h"
#endif // #ifdef CONFIG_OVMS_COMP_EXT12V


#define MODULE_GPIO_SW2 0 // SW2: firmware download / factory reset

// ------------------------------- Default GPIO mapping ------------------------------------------
#ifdef CONFIG_OVMS_HW_DEFAULT_GPIO_MAP

#define VSPI_PIN_MISO 19
#define VSPI_PIN_MOSI 23
#define VSPI_PIN_CLK 18

#define VSPI_PIN_MCP2515_1_CS 5
#define VSPI_PIN_MAX7317_CS 21
#define VSPI_PIN_MCP2515_2_CS 27
Expand Down Expand Up @@ -135,6 +140,13 @@
#define MODEM_EGPIO_PWR 0
#define MODEM_EGPIO_DTR 3

#endif // CONFIG_HW_DEFAULT_GPIO_MAP

// ------------------------------ Alternative GPIO mapping ------------------------------------------
#ifdef CONFIG_OVMS_HW_REMAP_GPIO
#include CONFIG_OVMS_GPIO_MAP_FILE
#endif // CONFIG_OVMS_HW_REMAP_GPIO

class Peripherals : public InternalRamAllocated
{
public:
Expand Down
4 changes: 2 additions & 2 deletions vehicle/OVMS.V3/support/partitions4M.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000
factory, app, factory, 0x10000, 0x280000
store, data, fat, , 1M
factory, app, factory, 0x10000, 0x370000
store, data, fat, , 0x80000
Loading