Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/detect/ScanI2CTwoWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
type = AHT10;
break;
#endif
#if !defined(M5STACK_UNITC6L)
#if !defined(M5STACK_UNITC6L) && !defined(ARDUINO_NESSO_N1)
case INA_ADDR:
case INA_ADDR_ALTERNATE:
case INA_ADDR_WAVESHARE_UPS:
Expand Down
8 changes: 7 additions & 1 deletion src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
extern SX1509 gpioExtender;
#endif

#ifdef TFT_BL_EXT
#include "GpioExtLogic.h"
#endif

#ifdef TFT_MESH_OVERRIDE
uint16_t TFT_MESH = TFT_MESH_OVERRIDE;
#else
Expand Down Expand Up @@ -485,7 +489,7 @@ class LGFX : public lgfx::LGFX_Device
lgfx::Bus_SPI _bus_instance;
lgfx::Light_PWM _light_instance;
#if HAS_TOUCHSCREEN
#if defined(T_WATCH_S3) || defined(ELECROW)
#if defined(T_WATCH_S3) || defined(ELECROW) || defined(ARDUINO_NESSO_N1)
lgfx::Touch_FT5x06 _touch_instance;
#elif defined(HELTEC_V4_TFT)
lgfx::TOUCH_CHSC6X _touch_instance;
Expand Down Expand Up @@ -1163,6 +1167,8 @@ TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g
virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio
p = virtPin;
}
#elif defined(TFT_BL_EXT)
GpioPin *p = new GpioExtPin(TFT_BL_EXT);
#else
GpioPin *p = new GpioVirtPin(); // Just simulate a pin
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/draw/MenuHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ void menuHandler::TFTColorPickerMenu(OLEDDisplay *display)
}

#if defined(HELTEC_MESH_NODE_T114) || defined(HELTEC_VISION_MASTER_T190) || defined(T_DECK) || defined(T_LORA_PAGER) || \
HAS_TFT || defined(HACKADAY_COMMUNICATOR)
HAS_TFT || defined(HACKADAY_COMMUNICATOR) || defined(ARDUINO_NESSO_N1)
const ScreenColor &color = option.value;
if (color.useVariant) {
LOG_INFO("Setting color to system default or defined variant");
Expand Down Expand Up @@ -2358,7 +2358,7 @@ void menuHandler::screenOptionsMenu()

// Only show screen color for TFT displays
#if defined(HELTEC_MESH_NODE_T114) || defined(HELTEC_VISION_MASTER_T190) || defined(T_DECK) || defined(T_LORA_PAGER) || \
HAS_TFT || defined(HACKADAY_COMMUNICATOR)
HAS_TFT || defined(HACKADAY_COMMUNICATOR) || defined(ARDUINO_NESSO_N1)
optionsArray[options] = "Screen Color";
optionsEnumArray[options++] = ScreenColor;
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/input/i2cButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "meshUtils.h"

#include "configuration.h"
#if defined(M5STACK_UNITC6L)
#if defined(M5STACK_UNITC6L) || defined(ARDUINO_NESSO_N1)

#include "MeshService.h"
#include "RadioLibInterface.h"
Expand Down Expand Up @@ -92,4 +92,4 @@ int32_t i2cButtonThread::runOnce()
}
return 50;
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/input/i2cButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "OneButton.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#if defined(M5STACK_UNITC6L)
#if defined(M5STACK_UNITC6L) || defined(ARDUINO_NESSO_N1)

class i2cButtonThread : public Observable<const InputEvent *>, public concurrency::OSThread
{
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void setup()
#endif
#endif

#if defined(M5STACK_UNITC6L)
#if defined(M5STACK_UNITC6L) || defined(ARDUINO_NESSO_N1)
pinMode(LORA_CS, OUTPUT);
digitalWrite(LORA_CS, 1);
c6l_init();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void setupModules()
#endif
cardKbI2cImpl = new CardKbI2cImpl();
cardKbI2cImpl->init();
#if defined(M5STACK_UNITC6L)
#if defined(M5STACK_UNITC6L) || defined(ARDUINO_NESSO_N1)
i2cButton = new i2cButtonThread("i2cButtonThread");
#endif
#ifdef INPUTBROKER_MATRIX_TYPE
Expand Down
12 changes: 12 additions & 0 deletions variants/esp32c6/arduino_nesso_n1/GpioExtLogic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "GpioExtLogic.h"
#include <assert.h>

void GpioExtPin::set(bool value)
{
gpio_ext_set(this->address, this->pin, value);
}

uint8_t GpioExtPin::get()
{
return gpio_ext_get(this->address, this->pin);
}
14 changes: 14 additions & 0 deletions variants/esp32c6/arduino_nesso_n1/GpioExtLogic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "GpioLogic.h"

class GpioExtPin : public GpioPin
{
uint32_t num;

public:
GpioExtPin(uint16_t _pin) : pin(_pin & 0x3F), address(_pin & 0x100 ? 0x44 : 0x43){};
uint8_t pin;
uint8_t address;

void set(bool value);
uint8_t get();
};
22 changes: 22 additions & 0 deletions variants/esp32c6/arduino_nesso_n1/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#define USB_VID 0x303A
#define USB_PID 0x1001

static const uint8_t TX = -1;
static const uint8_t RX = -1;

static const uint8_t SDA = 10;
static const uint8_t SCL = 8;

// Default SPI will be mapped to Radio
static const uint8_t MOSI = 21;
static const uint8_t MISO = 22;
static const uint8_t SCK = 20;
static const uint8_t SS = 23;

#endif /* Pins_Arduino_h */

35 changes: 35 additions & 0 deletions variants/esp32c6/arduino_nesso_n1/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[env:arduino-nesso-n1]
extends = esp32c6_base
board = esp32-c6-devkitc-1
upload_protocol = esptool
build_unflags =
-D HAS_BLUETOOTH
-D MESHTASTIC_EXCLUDE_BLUETOOTH
-D HAS_WIFI
lib_deps =
${esp32c6_base.lib_deps}
h2zero/NimBLE-Arduino@^2.3.6
lovyan03/LovyanGFX@^1.2.0
https://github.com/mverch67/BQ27220/archive/07d92be846abd8a0258a50c23198dac0858b22ed.zip
build_flags =
${esp32c6_base.build_flags}
-D PRIVATE_HW
-D ARDUINO_NESSO_N1
-I variants/esp32c6/arduino_nesso_n1
-DMESHTASTIC_EXCLUDE_PAXCOUNTER=1
-DSOC_USB_OTG_SUPPORTED=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1
-D HAS_BLUETOOTH=1
Comment thread
mverch67 marked this conversation as resolved.
-D HAS_WIRE=1
-DCONFIG_BT_NIMBLE_EXT_ADV=1
-DCONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=2
-D NIMBLE_TWO
-D CORE_DEBUG_LEVEL=5
-D _ESP_LOGLEVEL_=5
monitor_speed=115200
lib_ignore =
NonBlockingRTTTL
libpax
build_src_filter =
${esp32c6_base.build_src_filter} +<../variants/esp32c6/arduino_nesso_n1>
127 changes: 127 additions & 0 deletions variants/esp32c6/arduino_nesso_n1/variant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "driver/gpio.h"
#include <Arduino.h>
#include <Wire.h>
// I2C device addr
#define PI4IO_M_ADDR 0x43
#define PI4IO_M_ADDR2 0x44

// PI4IO registers
#define PI4IO_REG_CHIP_RESET 0x01
#define PI4IO_REG_IO_DIR 0x03
#define PI4IO_REG_OUT_SET 0x05
#define PI4IO_REG_OUT_H_IM 0x07
#define PI4IO_REG_IN_DEF_STA 0x09
#define PI4IO_REG_PULL_EN 0x0B
#define PI4IO_REG_PULL_SEL 0x0D
#define PI4IO_REG_IN_STA 0x0F
#define PI4IO_REG_INT_MASK 0x11
#define PI4IO_REG_IRQ_STA 0x13
// PI4IO

#define setbit(x, y) x |= (0x01 << y)
#define clrbit(x, y) x &= ~(0x01 << y)
#define reversebit(x, y) x ^= (0x01 << y)
#define getbit(x, y) ((x) >> (y)&0x01)

void i2c_read_byte(uint8_t addr, uint8_t reg, uint8_t *value)
{
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(addr, 1);
*value = Wire.read();
}

/*******************************************************************/
void i2c_write_byte(uint8_t addr, uint8_t reg, uint8_t value)
{
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
/*******************************************************************/
void c6l_init()
{
// P7 LoRa Reset
// P6 RF Switch
// P5 LNA Enable
// P1 KEY2
// P0 KEY1
// P107 LED_BUILTIN
// P106 LCD_BACKLIGHT
// P105 VIN_DETECT
// P102 GROVE_POWER_EN
// P101 LCD_RESET
// P100 POWEROFF

printf("pi4io_init\n");
uint8_t in_data;
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_CHIP_RESET, 0xFF);
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_read_byte(PI4IO_M_ADDR, PI4IO_REG_CHIP_RESET, &in_data);
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_IO_DIR, 0b11100000); // 0: input 1: output
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_OUT_H_IM, 0b00011100); // Output High-Impedance, 1 high-impedance
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_PULL_SEL, 0b11100011); // pull up/down select, 0 down, 1 up
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_PULL_EN, 0b11100011); // pull up/down enable, 0 disable, 1 enable
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_IN_DEF_STA, 0b00000011); // P0 P1 Default state HIGH, interrupt when pressed
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_INT_MASK, 0b11111100); // P0 P1 Interrupt 0 enable, 1 disable
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_OUT_SET, 0b11100000); // default output to 0
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_read_byte(PI4IO_M_ADDR, PI4IO_REG_IRQ_STA, &in_data); // Read IRQ_STA clear register

i2c_read_byte(PI4IO_M_ADDR, PI4IO_REG_OUT_SET, &in_data);
setbit(in_data, 6); // HIGH
i2c_write_byte(PI4IO_M_ADDR, PI4IO_REG_OUT_SET, in_data);

i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_CHIP_RESET, 0xFF);
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_read_byte(PI4IO_M_ADDR2, PI4IO_REG_CHIP_RESET, &in_data);
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_IO_DIR, 0b11000110); // 0: input 1: output
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_OUT_H_IM, 0b00111000); // Output High-Impedance, 1 high-impedance
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_PULL_SEL, 0b11000111); // pull up/down select, 0 down, 1 up
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_PULL_EN, 0b11000111); // pull up/down enable, 0 disable, 1 enable
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_IN_DEF_STA, 0b00000000); // P0 P1 Default state HIGH, interrupt when pressed
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_INT_MASK, 0b11111111); // P0 P1 Interrupt 0 enable, 1 disable
vTaskDelay(10 / portTICK_PERIOD_MS);
i2c_write_byte(PI4IO_M_ADDR2, PI4IO_REG_OUT_SET, 0b11000110); // default output to 0

// AW32001E - address 0x49
// charge current 256mA (default 128mA)
i2c_write_byte(0x49, 0x2, 0x1f);
// charge voltage 4.200(default)
// disable watch dog timer (default: 0x1f)
i2c_write_byte(0x49, 0x5, 0x1a);
// UVLO: 2.580 (default: 2.760), charge enable, disable HIZ (default: 0xac)
i2c_write_byte(0x49, 0x1, 0xa2);
// DPM 4.520 (default)
i2c_write_byte(0x49, 0x0, 0x8f);
}

void gpio_ext_set(uint8_t address, uint8_t pin, bool value)
{
uint8_t in_data;
i2c_read_byte(address, PI4IO_REG_OUT_SET, &in_data);
value ? setbit(in_data, pin) : clrbit(in_data, pin);
i2c_write_byte(address, PI4IO_REG_OUT_SET, in_data);
}

uint8_t gpio_ext_get(uint8_t address, uint8_t pin)
{
uint8_t in_data;
i2c_read_byte(address, PI4IO_REG_OUT_SET, &in_data);
return getbit(in_data, pin);
}
Loading