kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Initial C++ setup for Yukon
rodzic
f0c7f2a9ae
commit
6fabb0255d
|
@ -40,6 +40,11 @@ namespace pimoroni {
|
|||
i2c_write_blocking(i2c, address, buffer, 2, false);
|
||||
}
|
||||
|
||||
void I2C::reg_write_uint16(uint8_t address, uint8_t reg, uint16_t value) {
|
||||
uint8_t buffer[3] = { reg, (uint8_t)(value & 0xFF), (uint8_t)(value >> 8) };
|
||||
i2c_write_blocking(i2c, address, buffer, 3, false);
|
||||
}
|
||||
|
||||
uint8_t I2C::reg_read_uint8(uint8_t address, uint8_t reg) {
|
||||
uint8_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, false);
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace pimoroni {
|
|||
i2c_inst_t* pin_to_inst(uint pin);
|
||||
|
||||
void reg_write_uint8(uint8_t address, uint8_t reg, uint8_t value);
|
||||
void reg_write_uint16(uint8_t address, uint8_t reg, uint16_t value);
|
||||
uint8_t reg_read_uint8(uint8_t address, uint8_t reg);
|
||||
uint16_t reg_read_uint16(uint8_t address, uint8_t reg);
|
||||
int16_t reg_read_int16(uint8_t address, uint8_t reg);
|
||||
|
|
|
@ -43,4 +43,5 @@ add_subdirectory(st7567)
|
|||
add_subdirectory(psram_display)
|
||||
add_subdirectory(shiftregister)
|
||||
add_subdirectory(inky73)
|
||||
add_subdirectory(mlx90640)
|
||||
add_subdirectory(mlx90640)
|
||||
add_subdirectory(tca9555)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
include(tca9555.cmake)
|
|
@ -0,0 +1,10 @@
|
|||
set(DRIVER_NAME tca9555)
|
||||
add_library(${DRIVER_NAME} INTERFACE)
|
||||
|
||||
target_sources(${DRIVER_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp)
|
||||
|
||||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_i2c pimoroni_i2c)
|
|
@ -0,0 +1,367 @@
|
|||
#include "tca9555.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
#define HIGH_BYTE(index) (((index) * 2u) + 1u)
|
||||
#define LOW_BYTE(index) (((index) * 2u))
|
||||
#define IS_PORT1(gpio) (((gpio) % TCA9555::GPIO_COUNT) >= 8u)
|
||||
#define GPIO_BYTE(gpio) ((gpio) >> 3u)
|
||||
#define GPIO_BIT_MASK(gpio) (1u << ((gpio) % 8u))
|
||||
#define CHIP_FROM_GPIO(gpio) ((gpio) / TCA9555::GPIO_COUNT)
|
||||
//#define ADDRESS_FROM_GPIO(gpio) (tca9555r_addresses[CHIP_FROM_GPIO(gpio)])
|
||||
|
||||
void TCA9555::init() {
|
||||
if(interrupt != PIN_UNUSED) {
|
||||
gpio_set_function(interrupt, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(interrupt, GPIO_IN);
|
||||
gpio_set_pulls(interrupt, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
// i2c helper methods
|
||||
i2c_inst_t* TCA9555::get_i2c() const {
|
||||
return i2c->get_i2c();
|
||||
}
|
||||
|
||||
int TCA9555::get_address() const {
|
||||
return address;
|
||||
}
|
||||
|
||||
int TCA9555::get_sda() const {
|
||||
return i2c->get_sda();
|
||||
}
|
||||
|
||||
int TCA9555::get_scl() const {
|
||||
return i2c->get_scl();
|
||||
}
|
||||
|
||||
int TCA9555::get_int() const {
|
||||
return interrupt;
|
||||
}
|
||||
|
||||
bool TCA9555::get_gpio_input(uint gpio) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? INPUT_PORT1 : INPUT_PORT0;
|
||||
uint8_t input_state = i2c->reg_read_uint8(address, reg);
|
||||
return (input_state & GPIO_BIT_MASK(gpio)) != 0;
|
||||
}
|
||||
|
||||
bool TCA9555::get_gpio_output(uint gpio) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? OUTPUT_PORT1 : OUTPUT_PORT0;
|
||||
uint8_t output_state = i2c->reg_read_uint8(address, reg);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[GPIO_BYTE(gpio)] = output_state;
|
||||
#endif
|
||||
return (output_state & GPIO_BIT_MASK(gpio)) != 0;
|
||||
}
|
||||
|
||||
bool TCA9555::get_gpio_config(uint gpio) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? CONFIGURATION_PORT1 : CONFIGURATION_PORT0;
|
||||
uint8_t config_state = i2c->reg_read_uint8(address, reg);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[GPIO_BYTE(gpio)] = config_state;
|
||||
#endif
|
||||
return (config_state & GPIO_BIT_MASK(gpio)) == 0;
|
||||
}
|
||||
|
||||
bool TCA9555::get_gpio_polarity(uint gpio) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? POLARITY_PORT1 : POLARITY_PORT0;
|
||||
uint8_t polarity_state = i2c->reg_read_uint8(address, reg);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[GPIO_BYTE(gpio)] = polarity_state;
|
||||
#endif
|
||||
return (polarity_state & GPIO_BIT_MASK(gpio)) != 0;
|
||||
}
|
||||
|
||||
void TCA9555::set_gpio_output(uint gpio, bool value) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? OUTPUT_PORT1 : OUTPUT_PORT0;
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint8_t output_state = stored_output_state[GPIO_BYTE(tca_gpio)];
|
||||
#else
|
||||
uint8_t output_state = i2c->reg_read_uint8(address, reg);
|
||||
#endif
|
||||
uint8_t new_output_state;
|
||||
if (value) {
|
||||
new_output_state = output_state | GPIO_BIT_MASK(gpio);
|
||||
} else {
|
||||
new_output_state = output_state & ~GPIO_BIT_MASK(gpio);
|
||||
}
|
||||
|
||||
if (new_output_state != output_state) {
|
||||
i2c->reg_write_uint8(address, reg, new_output_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[GPIO_BYTE(gpio)] = new_output_state;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void TCA9555::set_gpio_config(uint gpio, bool output) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? CONFIGURATION_PORT1 : CONFIGURATION_PORT0;
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint8_t config_state = tca9555r_config_state[GPIO_BYTE(gpio)];
|
||||
#else
|
||||
uint8_t config_state = i2c->reg_read_uint8(address, reg);
|
||||
#endif
|
||||
uint8_t new_config_state;
|
||||
if (output) {
|
||||
new_config_state = config_state & ~GPIO_BIT_MASK(gpio);
|
||||
} else {
|
||||
new_config_state = config_state | GPIO_BIT_MASK(gpio);
|
||||
}
|
||||
|
||||
if (new_config_state != config_state) {
|
||||
i2c->reg_write_uint8(address, reg, new_config_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[GPIO_BYTE(gpio)] = new_config_state;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void TCA9555::set_gpio_polarity(uint gpio, bool polarity) {
|
||||
assert(gpio < GPIO_COUNT);
|
||||
//busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
|
||||
//uint8_t address = ADDRESS_FROM_GPIO(tca_gpio);
|
||||
|
||||
uint8_t reg = IS_PORT1(gpio) ? POLARITY_PORT1 : POLARITY_PORT0;
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint8_t polarity_state = tca9555r_polarity_state[GPIO_BYTE(tca_gpio)];
|
||||
#else
|
||||
uint8_t polarity_state = i2c->reg_read_uint8(address, reg);
|
||||
#endif
|
||||
uint8_t new_polarity_state;
|
||||
if (polarity) {
|
||||
new_polarity_state = polarity_state | GPIO_BIT_MASK(gpio);
|
||||
} else {
|
||||
new_polarity_state = polarity_state & ~GPIO_BIT_MASK(gpio);
|
||||
}
|
||||
|
||||
if (new_polarity_state != polarity_state) {
|
||||
i2c->reg_write_uint8(address, reg, new_polarity_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
tca9555r_output_state[GPIO_BYTE(gpio)] = new_polarity_state;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t TCA9555::get_input_port() {
|
||||
return i2c->reg_read_uint16(address, INPUT_PORT0);
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_input_port_low() {
|
||||
return i2c->reg_read_uint8(address, INPUT_PORT0);
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_input_port_high() {
|
||||
return i2c->reg_read_uint8(address, INPUT_PORT1);
|
||||
}
|
||||
|
||||
uint16_t TCA9555::get_output_port() {
|
||||
uint16_t output_state = i2c->reg_read_uint16(address, OUTPUT_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[HIGH_BYTE(tca_index)] = (output_state >> 8);
|
||||
stored_output_state[LOW_BYTE(tca_index)] = (output_state & 0xFF);
|
||||
#endif
|
||||
return output_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_output_port_low() {
|
||||
uint8_t output_state = i2c->reg_read_uint8(address, OUTPUT_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[LOW_BYTE(tca_index)] = output_state;
|
||||
#endif
|
||||
return output_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_output_port_high() {
|
||||
uint8_t output_state = i2c->reg_read_uint8(address, OUTPUT_PORT1);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[HIGH_BYTE(tca_index)] = output_state;
|
||||
#endif
|
||||
return output_state;
|
||||
}
|
||||
|
||||
uint16_t TCA9555::get_config_port() {
|
||||
uint16_t config_state = i2c->reg_read_uint16(address, CONFIGURATION_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[HIGH_BYTE(tca_index)] = (config_state >> 8);
|
||||
stored_config_state[LOW_BYTE(tca_index)] = (config_state & 0xFF);
|
||||
#endif
|
||||
return config_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_config_port_low() {
|
||||
uint8_t config_state = i2c->reg_read_uint8(address, CONFIGURATION_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[LOW_BYTE(tca_index)] = config_state;
|
||||
#endif
|
||||
return config_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_config_port_high() {
|
||||
uint8_t config_state = i2c->reg_read_uint8(address, CONFIGURATION_PORT1);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[HIGH_BYTE(tca_index)] = config_state;
|
||||
#endif
|
||||
return config_state;
|
||||
}
|
||||
|
||||
uint16_t TCA9555::get_polarity_port() {
|
||||
uint16_t polarity_state = i2c->reg_read_uint16(address, POLARITY_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[HIGH_BYTE(tca_index)] = (polarity_state >> 8);
|
||||
stored_polarity_state[LOW_BYTE(tca_index)] = (polarity_state & 0xFF);
|
||||
#endif
|
||||
return polarity_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_polarity_port_low() {
|
||||
uint8_t polarity_state = i2c->reg_read_uint8(address, POLARITY_PORT0);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[LOW_BYTE(tca_index)] = polarity_state;
|
||||
#endif
|
||||
return polarity_state;
|
||||
}
|
||||
|
||||
uint8_t TCA9555::get_polarity_port_high() {
|
||||
uint8_t polarity_state = i2c->reg_read_uint8(address, POLARITY_PORT1);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[HIGH_BYTE(tca_index)] = polarity_state;
|
||||
#endif
|
||||
return polarity_state;
|
||||
}
|
||||
|
||||
void TCA9555::set_output_port(uint16_t output_state) {
|
||||
i2c->reg_write_uint16(address, OUTPUT_PORT0, output_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[HIGH_BYTE(tca_index)] = (output_state >> 8);
|
||||
stored_output_state[LOW_BYTE(tca_index)] = (output_state & 0xFF);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_output_port_low(uint8_t output_state) {
|
||||
i2c->reg_write_uint8(address, OUTPUT_PORT0, output_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[LOW_BYTE(tca_index)] = output_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_output_port_high(uint8_t output_state) {
|
||||
i2c->reg_write_uint8(address, OUTPUT_PORT1, output_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_output_state[HIGH_BYTE(tca_index)] = output_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_config_port(uint16_t config_state) {
|
||||
i2c->reg_write_uint16(address, CONFIGURATION_PORT0, config_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[HIGH_BYTE(tca_index)] = (config_state >> 8);
|
||||
stored_config_state[LOW_BYTE(tca_index)] = (config_state & 0xFF);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_config_port_low(uint8_t config_state) {
|
||||
i2c->reg_write_uint8(address, CONFIGURATION_PORT0, config_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[LOW_BYTE(tca_index)] = config_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_config_port_high(uint8_t config_state) {
|
||||
i2c->reg_write_uint8(address, CONFIGURATION_PORT1, config_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_config_state[HIGH_BYTE(tca_index)] = config_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_polarity_port(uint16_t polarity_state) {
|
||||
i2c->reg_write_uint16(address, POLARITY_PORT0, polarity_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[HIGH_BYTE(tca_index)] = (polarity_state >> 8);
|
||||
stored_polarity_state[LOW_BYTE(tca_index)] = (polarity_state & 0xFF);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_polarity_port_low(uint8_t polarity_state) {
|
||||
i2c->reg_write_uint8(address, POLARITY_PORT0, polarity_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[LOW_BYTE(tca_index)] = polarity_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::set_polarity_port_high(uint8_t polarity_state) {
|
||||
i2c->reg_write_uint8(address, POLARITY_PORT1, polarity_state);
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
stored_polarity_state[HIGH_BYTE(tca_index)] = polarity_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TCA9555::change_output_mask(uint16_t mask, uint16_t state) {
|
||||
uint8_t low_mask = (uint8_t)(mask & 0xFF);
|
||||
uint8_t low_state = (uint8_t)(state & 0xFF);
|
||||
uint8_t high_mask = (uint8_t)(mask >> 8);
|
||||
uint8_t high_state = (uint8_t)(state >> 8);
|
||||
bool low_changed = low_mask > 0;
|
||||
bool high_changed = high_mask > 0;
|
||||
if (low_changed && high_changed) {
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint16_t output_state = (stored_output_state[HIGH_BYTE(chip)] << 8) | stored_output_state[LOW_BYTE(chip)];
|
||||
#else
|
||||
uint16_t output_state = get_output_port();
|
||||
#endif
|
||||
uint16_t new_output_state = output_state;
|
||||
new_output_state &= ~mask; // Clear the mask bits
|
||||
new_output_state |= state; // Set the state bits
|
||||
if (new_output_state != output_state) {
|
||||
set_output_port(new_output_state);
|
||||
}
|
||||
} else if (low_changed) {
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint8_t output_state = stored_output_state[LOW_BYTE(chip)];
|
||||
#else
|
||||
uint8_t output_state = get_output_port_low();
|
||||
#endif
|
||||
uint8_t new_output_state = (output_state & ~low_mask) | low_state;
|
||||
if (new_output_state != output_state) {
|
||||
set_output_port_low(new_output_state);
|
||||
}
|
||||
} else if (high_changed) {
|
||||
#if TCA9555R_LOCAL_MEMORY
|
||||
uint8_t output_state = tca9555r_output_state[HIGH_BYTE(chip)];
|
||||
#else
|
||||
uint8_t output_state = get_output_port_high();
|
||||
#endif
|
||||
uint8_t new_output_state = (output_state & ~high_mask) | high_state;
|
||||
if (new_output_state != output_state) {
|
||||
set_output_port_high(new_output_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
#pragma once
|
||||
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
#include "common/pimoroni_common.hpp"
|
||||
#include "common/pimoroni_i2c.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
class TCA9555 {
|
||||
//--------------------------------------------------
|
||||
// Constants
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint DEFAULT_I2C_ADDRESS = 0x20;
|
||||
static const int PARAM_UNUSED = -1;
|
||||
static const uint8_t GPIO_COUNT = 16;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Enums
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
enum Registers : uint8_t {
|
||||
INPUT_PORT0 = 0x00,
|
||||
INPUT_PORT1 = 0x01,
|
||||
OUTPUT_PORT0 = 0x02,
|
||||
OUTPUT_PORT1 = 0x03,
|
||||
POLARITY_PORT0 = 0x04,
|
||||
POLARITY_PORT1 = 0x05,
|
||||
CONFIGURATION_PORT0 = 0x06,
|
||||
CONFIGURATION_PORT1 = 0x07
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Variables
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
I2C *i2c;
|
||||
|
||||
// Interface pins with our standard defaults where appropriate
|
||||
uint address = DEFAULT_I2C_ADDRESS;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
uint8_t stored_output_state[2] = {0};
|
||||
uint8_t stored_config_state[2] = {0};
|
||||
uint8_t stored_polarity_state[2] = {0};
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
//TCA9555() :
|
||||
// TCA9555(new I2C()) {}
|
||||
|
||||
TCA9555(uint address) :
|
||||
TCA9555(new I2C(), address) {}
|
||||
|
||||
TCA9555(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Methods
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
void init();
|
||||
|
||||
// I2C instance details access methods
|
||||
i2c_inst_t* get_i2c() const;
|
||||
int get_address() const;
|
||||
int get_sda() const;
|
||||
int get_scl() const;
|
||||
int get_int() const;
|
||||
|
||||
bool get_gpio_input(uint gpio);
|
||||
bool get_gpio_output(uint gpio);
|
||||
bool get_gpio_config(uint gpio);
|
||||
bool get_gpio_polarity(uint gpio);
|
||||
|
||||
void set_gpio_output(uint gpio, bool value);
|
||||
void set_gpio_config(uint gpio, bool output);
|
||||
void set_gpio_polarity(uint gpio, bool polarity);
|
||||
|
||||
uint16_t get_input_port();
|
||||
uint8_t get_input_port_low();
|
||||
uint8_t get_input_port_high();
|
||||
|
||||
uint16_t get_output_port();
|
||||
uint8_t get_output_port_low();
|
||||
uint8_t get_output_port_high();
|
||||
|
||||
uint16_t get_config_port();
|
||||
uint8_t get_config_port_low();
|
||||
uint8_t get_config_port_high();
|
||||
|
||||
uint16_t get_polarity_port();
|
||||
uint8_t get_polarity_port_low();
|
||||
uint8_t get_polarity_port_high();
|
||||
|
||||
void set_output_port(uint16_t output_state);
|
||||
void set_output_port_low(uint8_t output_state);
|
||||
void set_output_port_high(uint8_t output_state);
|
||||
|
||||
void set_config_port(uint16_t config_state);
|
||||
void set_config_port_low(uint8_t config_state);
|
||||
void set_config_port_high(uint8_t config_state);
|
||||
|
||||
void set_polarity_port(uint16_t polarity_state);
|
||||
void set_polarity_port_low(uint8_t polarity_state);
|
||||
void set_polarity_port_high(uint8_t polarity_state);
|
||||
|
||||
void change_output_mask(uint16_t mask, uint16_t state);
|
||||
};
|
||||
|
||||
}
|
|
@ -62,3 +62,4 @@ add_subdirectory(galactic_unicorn)
|
|||
add_subdirectory(gfx_pack)
|
||||
add_subdirectory(cosmic_unicorn)
|
||||
add_subdirectory(stellar_unicorn)
|
||||
add_subdirectory(yukon)
|
||||
|
|
|
@ -44,3 +44,4 @@ add_subdirectory(gfx_pack)
|
|||
add_subdirectory(interstate75)
|
||||
add_subdirectory(cosmic_unicorn)
|
||||
add_subdirectory(stellar_unicorn)
|
||||
add_subdirectory(yukon)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
include(yukon.cmake)
|
|
@ -0,0 +1,10 @@
|
|||
add_library(yukon INTERFACE)
|
||||
|
||||
target_sources(yukon INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/yukon.cpp
|
||||
)
|
||||
|
||||
target_include_directories(yukon INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(yukon INTERFACE pico_stdlib pico_graphics tca9555 hardware_adc)
|
|
@ -0,0 +1,129 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "hardware/irq.h"
|
||||
#include "hardware/adc.h"
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
#include "yukon.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
const SLOT Yukon::SLOT1 = {
|
||||
1, // ID
|
||||
0, // FAST1
|
||||
1, // FAST2
|
||||
2, // FAST3
|
||||
3, // FAST4
|
||||
{0, 3}, // SLOW1
|
||||
{0, 4}, // SLOW2
|
||||
{0, 5}, // SLOW3
|
||||
0, // ADC1_ADDR (0b0000)
|
||||
3, // ADC2_TEMP_ADDR (0b0011)
|
||||
};
|
||||
|
||||
const SLOT Yukon::SLOT2 = {
|
||||
2, // ID
|
||||
4, // FAST1
|
||||
5, // FAST2
|
||||
6, // FAST3
|
||||
7, // FAST4
|
||||
{0, 0}, // SLOW1
|
||||
{0, 1}, // SLOW2
|
||||
{0, 2}, // SLOW3
|
||||
1, // ADC1_ADDR (0b0001)
|
||||
6, // ADC2_TEMP_ADDR (0b0110)
|
||||
};
|
||||
|
||||
const SLOT Yukon::SLOT3 = {
|
||||
3, // ID
|
||||
8, // FAST1
|
||||
9, // FAST2
|
||||
10, // FAST3
|
||||
11, // FAST4
|
||||
{0, 8}, // SLOW1
|
||||
{0, 9}, // SLOW2
|
||||
{0, 10}, // SLOW3
|
||||
4, // ADC1_ADDR (0b0100)
|
||||
2, // ADC2_TEMP_ADDR (0b0010)
|
||||
};
|
||||
|
||||
const SLOT Yukon::SLOT4 = {
|
||||
4, // ID
|
||||
12, // FAST1
|
||||
13, // FAST2
|
||||
14, // FAST3
|
||||
15, // FAST4
|
||||
{1, 7}, // SLOW1
|
||||
{1, 5}, // SLOW2
|
||||
{1, 6}, // SLOW3
|
||||
5, // ADC1_ADDR (0b0101)
|
||||
7, // ADC2_TEMP_ADDR (0b0111)
|
||||
};
|
||||
|
||||
const SLOT Yukon::SLOT5 = {
|
||||
5, // ID
|
||||
16, // FAST1
|
||||
17, // FAST2
|
||||
18, // FAST3
|
||||
19, // FAST4
|
||||
{1, 15}, // SLOW1
|
||||
{1, 14}, // SLOW2
|
||||
{1, 13}, // SLOW3
|
||||
8, // ADC1_ADDR (0b1000)
|
||||
11, // ADC2_TEMP_ADDR (0b1011)
|
||||
};
|
||||
|
||||
const SLOT Yukon::SLOT6 = {
|
||||
6, // ID
|
||||
20, // FAST1
|
||||
21, // FAST2
|
||||
22, // FAST3
|
||||
23, // FAST4
|
||||
{1, 10}, // SLOW1
|
||||
{1, 12}, // SLOW2
|
||||
{1, 11}, // SLOW3
|
||||
9, // ADC1_ADDR (0b1001)
|
||||
10, // ADC2_TEMP_ADDR (0b1010)
|
||||
};
|
||||
|
||||
|
||||
const TCA Yukon::MAIN_EN = {0, 6};
|
||||
const TCA Yukon::USER_SW = {0, 7};
|
||||
|
||||
const TCA Yukon::ADC_ADDR_1 = {0, 12};
|
||||
const TCA Yukon::ADC_ADDR_2 = {0, 13};
|
||||
const TCA Yukon::ADC_ADDR_3 = {0, 14};
|
||||
const TCA Yukon::ADC_MUX_EN_1 = {0, 15};
|
||||
const TCA Yukon::ADC_MUX_EN_2 = {0, 11};
|
||||
|
||||
const TCA Yukon::SW_A = {1, 1};
|
||||
const TCA Yukon::SW_B = {1, 2};
|
||||
const TCA Yukon::LED_A = {1, 3};
|
||||
const TCA Yukon::LED_B = {1, 4};
|
||||
|
||||
const TCA Yukon::LCD_BL = {1, 0};
|
||||
const TCA Yukon::LCD_DC = {1, 8};
|
||||
const TCA Yukon::LCD_CS = {1, 9};
|
||||
|
||||
Yukon::~Yukon() {
|
||||
}
|
||||
|
||||
void Yukon::init() {
|
||||
tca0.init();
|
||||
tca1.init();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void Yukon::reset() {
|
||||
// Set the first IO expander's initial state
|
||||
tca0.set_output_port(0x0000);
|
||||
tca0.set_polarity_port(0x0000);
|
||||
tca0.set_config_port(0x07BF);
|
||||
|
||||
// Set the second IO expander's initial state
|
||||
tca1.set_output_port(0x0000);
|
||||
tca1.set_polarity_port(0x0000);
|
||||
tca1.set_config_port(0xFCE6);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
#pragma once
|
||||
|
||||
#include "pico_graphics.hpp"
|
||||
#include "common/pimoroni_common.hpp"
|
||||
#include "drivers/tca9555/tca9555.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
struct TCA {
|
||||
uint CHIP;
|
||||
uint GPIO;
|
||||
};
|
||||
|
||||
struct SLOT {
|
||||
uint ID;
|
||||
uint FAST1;
|
||||
uint FAST2;
|
||||
uint FAST3;
|
||||
uint FAST4;
|
||||
TCA SLOW1;
|
||||
TCA SLOW2;
|
||||
TCA SLOW3;
|
||||
uint ADC1_ADDR;
|
||||
uint ADC2_TEMP_ADDR;
|
||||
};
|
||||
|
||||
class Yukon {
|
||||
public:
|
||||
static const SLOT SLOT1;
|
||||
static const SLOT SLOT2;
|
||||
static const SLOT SLOT3;
|
||||
static const SLOT SLOT4;
|
||||
static const SLOT SLOT5;
|
||||
static const SLOT SLOT6;
|
||||
|
||||
static const uint NUM_SLOTS = 6;
|
||||
|
||||
static const uint SDA = 24;
|
||||
static const uint SCL = 25;
|
||||
|
||||
static const uint GP26 = 26;
|
||||
static const uint GP27 = 27;
|
||||
|
||||
static const uint INT = 28;
|
||||
|
||||
static const uint SHARED_ADC = 29;
|
||||
|
||||
static const TCA MAIN_EN; // {0, 6}
|
||||
static const TCA USER_SW; // {0, 7}
|
||||
|
||||
static const TCA ADC_ADDR_1; // {0, 12}
|
||||
static const TCA ADC_ADDR_2; // {0, 13}
|
||||
static const TCA ADC_ADDR_3; // {0, 14}
|
||||
static const TCA ADC_MUX_EN_1; // {0, 15}
|
||||
static const TCA ADC_MUX_EN_2; // {0, 11}
|
||||
|
||||
static const TCA SW_A; // {1, 1}
|
||||
static const TCA SW_B; // {1, 2}
|
||||
static const TCA LED_A; // {1, 3}
|
||||
static const TCA LED_B; // {1, 4}
|
||||
|
||||
static const TCA LCD_BL; // {1, 0}
|
||||
static const TCA LCD_DC; // {1, 8}
|
||||
static const TCA LCD_CS; // {1, 9}
|
||||
|
||||
static const uint CURRENT_SENSE_ADDR = 12; // 0b1100
|
||||
static const uint TEMP_SENSE_ADDR = 13; // 0b1101
|
||||
static const uint VOLTAGE_SENSE_ADDR = 14; // 0b1110
|
||||
static const uint EX_ADC_ADDR = 15; // 0b1111
|
||||
private:
|
||||
I2C i2c;
|
||||
TCA9555 tca0;
|
||||
TCA9555 tca1;
|
||||
|
||||
public:
|
||||
Yukon() :
|
||||
i2c(24, 25),
|
||||
tca0(&i2c, 0x20),
|
||||
tca1(&i2c, 0x26) {}
|
||||
|
||||
~Yukon();
|
||||
|
||||
void init();
|
||||
void reset();
|
||||
};
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue