Skip to content
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
38 changes: 35 additions & 3 deletions src/M5Unified.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static constexpr const uint8_t _pin_table_i2c_ex_in[][5] = {
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
{ board_t::board_unknown , 255 ,255 , GPIO_NUM_0 ,GPIO_NUM_1 },
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
{ board_t::board_M5UnitC6L ,GPIO_NUM_8 ,GPIO_NUM_10 , 255 ,255 },
{ board_t::board_M5UnitC6L , 255 , 255 , 255 ,255 },
{ board_t::board_ArduinoNessoN1,GPIO_NUM_8 ,GPIO_NUM_10 , GPIO_NUM_8 ,GPIO_NUM_10 },
{ board_t::board_unknown , 255 ,255 , GPIO_NUM_1 ,GPIO_NUM_2 }, // NanoC6
#elif defined (CONFIG_IDF_TARGET_ESP32P4)
Expand Down Expand Up @@ -123,7 +123,7 @@ static constexpr const uint8_t _pin_table_port_bc[][5] = {
{ board_t::board_M5PowerHub , 255 , 255 , GPIO_NUM_1 ,GPIO_NUM_2 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
{ board_t::board_M5UnitC6L ,GPIO_NUM_4 ,GPIO_NUM_5 , GPIO_NUM_4 ,GPIO_NUM_5 },
{ board_t::board_M5UnitC6L ,GPIO_NUM_4 ,GPIO_NUM_5 , 255 ,255 },
{ board_t::board_ArduinoNessoN1,GPIO_NUM_4 ,GPIO_NUM_5 , GPIO_NUM_4 ,GPIO_NUM_5 },
#elif defined (CONFIG_IDF_TARGET_ESP32P4)
{ board_t::board_M5Tab5 , GPIO_NUM_17,GPIO_NUM_52, GPIO_NUM_7 ,GPIO_NUM_6 }, // Tab5
Expand Down Expand Up @@ -1383,9 +1383,32 @@ static constexpr const uint8_t _pin_table_mbus[][31] = {
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
case board_t::board_M5UnitC6L:
{
auto ioexp = new PI4IOE5V6408_Class(0x43);
In_SoftI2C.begin(I2C_NUM_0, 10, 8);
auto ioexp = new PI4IOE5V6408_Class(0x43, 400000, &In_SoftI2C);
ioexp->begin();
_io_expander[0].reset(ioexp);
// user button(P0) input pullup
_io_expander[0]->setDirection(0, false);
_io_expander[0]->setPullMode(0, true);
_io_expander[0]->setHighImpedance(0, false);
// sx1262 reset(P7)
_io_expander[0]->setDirection(7, true);
_io_expander[0]->setPullMode(7, false);
_io_expander[0]->setHighImpedance(7, false);
_io_expander[0]->digitalWrite(7, false);
delay(10);
_io_expander[0]->digitalWrite(7, true);
delay(10);
// LAN EN
_io_expander[0]->setDirection(5, true);
_io_expander[0]->setPullMode(5, false);
_io_expander[0]->setHighImpedance(5, false);
_io_expander[0]->digitalWrite(5, true);
// SW EN
_io_expander[0]->setDirection(6, true);
_io_expander[0]->setPullMode(6, false);
_io_expander[0]->setHighImpedance(6, false);
_io_expander[0]->digitalWrite(6, true);
}
break;
case board_t::board_ArduinoNessoN1:
Expand Down Expand Up @@ -2325,6 +2348,15 @@ static constexpr const uint8_t _pin_table_mbus[][31] = {
| (((raw_gpio32_39 >> (GPIO_NUM_39 & 31)) & 1)<<1); // gpio39 B
break;

case board_t::board_M5UnitC6L:
{
use_rawstate_bits = 0b00001;
auto exp = static_cast<PI4IOE5V6408_Class*>(_io_expander[0].get());
uint8_t value = exp->readRegister8(0x0F);
btn_rawstate_bits = (!(value & 0b00001) ? 0b00001 : 0); // BtnA
break;
}

default:
break;
}
Expand Down
32 changes: 16 additions & 16 deletions src/utility/I2C_Class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,56 @@ namespace m5
/// @param port_num I2C number. (I2C_NUM_0 or I2C_NUM_1).
/// @param pin_sda SDA pin number.
/// @param pin_scl SCL pin number.
void setPort(i2c_port_t port_num, int pin_sda, int pin_scl);
virtual void setPort(i2c_port_t port_num, int pin_sda, int pin_scl);

/// setup and begin I2C peripheral. (No communication is performed.)
/// @param port_num I2C number. (I2C_NUM_0 or I2C_NUM_1).
/// @param pin_sda SDA pin number.
/// @param pin_scl SCL pin number.
/// @return success(true) or failed(false).
bool begin(i2c_port_t port_num, int pin_sda, int pin_scl);
virtual bool begin(i2c_port_t port_num, int pin_sda, int pin_scl);

/// begin I2C peripheral. (No communication is performed.)
/// @return success(true) or failed(false).
bool begin(void);
virtual bool begin(void);

/// release I2C peripheral.
/// @return success(true) or failed(false).
bool release(void) const;
virtual bool release(void) const;

/// Sends the I2C start condition and the address of the slave.
/// @param address slave addr.
/// @param read bit of read flag. true=read / false=write.
/// @return success(true) or failed(false).
bool start(std::uint8_t address, bool read, std::uint32_t freq) const;
virtual bool start(std::uint8_t address, bool read, std::uint32_t freq) const;

/// Sends the I2C repeated start condition and the address of the slave.
/// @param address slave addr.
/// @param read bit of read flag. true=read / false=write.
/// @return success(true) or failed(false).
bool restart(std::uint8_t address, bool read, std::uint32_t freq) const;
virtual bool restart(std::uint8_t address, bool read, std::uint32_t freq) const;

/// Sends the I2C stop condition.
/// If an ACK error occurs, return false.
/// @return success(true) or failed(false).
bool stop(void) const;
virtual bool stop(void) const;

/// Send 1 byte of data.
/// @param data write data.
/// @return success(true) or failed(false).
bool write(std::uint8_t data) const;
virtual bool write(std::uint8_t data) const;

/// Send multiple bytes of data.
/// @param[in] data write data array.
/// @param length data array length.
/// @return success(true) or failed(false).
bool write(const std::uint8_t* data, std::size_t length) const;
virtual bool write(const std::uint8_t* data, std::size_t length) const;

/// Receive multiple bytes of data.
/// @param[out] result read data array.
/// @param length data array length.
/// @return success(true) or failed(false).
bool read(std::uint8_t* result, std::size_t length, bool last_nack = false) const;
virtual bool read(std::uint8_t* result, std::size_t length, bool last_nack = false) const;

//----------

Expand All @@ -82,42 +82,42 @@ namespace m5
/// @param[in] data write data array.
/// @param length data array length.
/// @return success(true) or failed(false).
bool writeRegister(std::uint8_t address, std::uint8_t reg, const std::uint8_t* data, std::size_t length, std::uint32_t freq) const;
virtual bool writeRegister(std::uint8_t address, std::uint8_t reg, const std::uint8_t* data, std::size_t length, std::uint32_t freq) const;

/// Read multiple bytes value from the register. Performs a series of communications from START to STOP.
/// @param address slave addr.
/// @param reg register number.
/// @param[out] result read data array.
/// @param length data array length.
/// @return success(true) or failed(false).
bool readRegister(std::uint8_t address, std::uint8_t reg, std::uint8_t* result, std::size_t length, std::uint32_t freq) const;
virtual bool readRegister(std::uint8_t address, std::uint8_t reg, std::uint8_t* result, std::size_t length, std::uint32_t freq) const;

/// Write a 1-byte value to the register. Performs a series of communications from START to STOP.
/// @param address slave addr.
/// @param reg register number.
/// @param data write data.
/// @return success(true) or failed(false).
bool writeRegister8(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;
virtual bool writeRegister8(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;

/// Read a 1-byte value from the register. Performs a series of communications from START to STOP.
/// @param address slave addr.
/// @param reg register number.
/// @return read value.
std::uint8_t readRegister8(std::uint8_t address, std::uint8_t reg, std::uint32_t freq) const;
virtual std::uint8_t readRegister8(std::uint8_t address, std::uint8_t reg, std::uint32_t freq) const;

/// Write a 1-byte value to the register by bit add operation. Performs a series of communications from START to STOP.
/// @param address slave addr.
/// @param reg register number.
/// @param data add bit data.
/// @return success(true) or failed(false).
bool bitOn(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;
virtual bool bitOn(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;

/// Write a 1-byte value to the register by bit erase operation. Performs a series of communications from START to STOP.
/// @param address slave addr.
/// @param reg register number.
/// @param data erase bit data.
/// @return success(true) or failed(false).
bool bitOff(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;
virtual bool bitOff(std::uint8_t address, std::uint8_t reg, std::uint8_t data, std::uint32_t freq) const;

/// execute I2C scan. (for 7bit address)
/// @param[out] result data array needs 120 Bytes.
Expand Down
5 changes: 4 additions & 1 deletion src/utility/IOExpander_Base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

#ifndef __M5_IOEXPANDER_BASE_H__
#define __M5_IOEXPANDER_BASE_H__

#include <stdint.h>
#include "I2C_Class.hpp"

#if CONFIG_IDF_TARGET_ESP32C6
#include "SoftI2C_Class.hpp"
#endif

namespace m5
{
class IOExpander_Base : public I2C_Device
Expand Down
3 changes: 3 additions & 0 deletions src/utility/PI4IOE5V6408_Class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include "IOExpander_Base.hpp"
#include "I2C_Class.hpp"
#if CONFIG_IDF_TARGET_ESP32C6
#include "SoftI2C_Class.hpp"
#endif

namespace m5
{
Expand Down
Loading