feat: Flysky PA01 support (#6392)

Co-authored-by: Malte Langermann <malte@langermann.net>
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
Co-authored-by: 3djc <3djc@gh.com>
Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
Co-authored-by: xlong <984929678@qq.com>
Co-authored-by: Peter Feerick <pfeerick@users.noreply.github.com>
This commit is contained in:
richardclli
2025-08-17 20:13:43 +10:00
committed by GitHub
co-authored by Malte Langermann philmoz 3djc raphaelcoeffic xlong Peter Feerick
parent 89e57df285
commit e89a4414ac
45 changed files with 5067 additions and 17 deletions
+124
View File
@@ -0,0 +1,124 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "aw9523b.h"
#define REG_INPUT 0x00
#define REG_OUTPUT 0x02
#define REG_DIRECTION 0x04
#define REG_INTERRUPT 0x06
#define REG_CONTROL 0x11
#define REG_LED_MODE 0x12
#define CTL_P0_DRIVE_MODE_OD 0
#define CTL_P0_DRIVE_MODE_PP (1<<4)
static int aw9523b_i2c_write16(aw9523b_t* dev, uint16_t reg, uint16_t value)
{
if (!dev->addr) return -1;
uint8_t val8 = value&0xFF;
if (i2c_write(dev->bus, dev->addr, reg, 1, (uint8_t*)&val8, 1) < 0) {
return -1;
}
val8 = (value>>8)&0xFF;
if (i2c_write(dev->bus, dev->addr, reg+1, 1, (uint8_t*)&val8, 1) < 0) {
return -1;
}
return 0;
}
int aw9523b_init(aw9523b_t* dev, etx_i2c_bus_t bus, uint16_t addr)
{
dev->bus = 0;
dev->addr = 0;
//dev->interrupt = 0;
dev->direction = 0xFFFF;
dev->output = 0;
if (i2c_init(bus) < 0) {
return -1;
}
if (i2c_dev_ready(bus, addr) < 0) {
return -1;
}
dev->bus = bus;
dev->addr = addr;
volatile uint8_t test = 0;
uint8_t tmp = CTL_P0_DRIVE_MODE_PP;
i2c_read(dev->bus, dev->addr, REG_CONTROL, 1, (uint8_t*)&test, 1);
i2c_write(dev->bus, dev->addr, REG_CONTROL, 1, (uint8_t*)&tmp, 1);
i2c_read(dev->bus, dev->addr, REG_CONTROL, 1, (uint8_t*)&test, 1);
aw9523b_i2c_write16(dev, REG_LED_MODE, 0xFFFF); // set all pins to GPIO mode not LED mode
aw9523b_i2c_write16(dev, REG_INTERRUPT, 0); // enable interrupts for all pins
return 0;
}
int aw9523b_set_direction(aw9523b_t* dev, uint16_t mask, uint16_t dir)
{
uint16_t tmp = dev->direction;
tmp &= ~mask;
tmp |= dir & mask;
if (aw9523b_i2c_write16(dev, REG_DIRECTION, tmp) < 0) {
return -1;
}
dev->direction = tmp;
return 0;
}
int aw9523b_write(aw9523b_t* dev, uint16_t mask, uint16_t value)
{
uint16_t tmp = dev->output;
tmp &= ~mask;
tmp |= value & mask;
if (aw9523b_i2c_write16(dev, REG_OUTPUT, tmp) < 0) {
return -1;
}
dev->output = tmp;
return 0;
}
int aw9523b_read(aw9523b_t* dev, uint16_t mask, uint16_t* value)
{
if (!dev->addr) return -1;
uint16_t tmp;
uint8_t tmp8;
if (i2c_read(dev->bus, dev->addr, REG_INPUT, 1, (uint8_t*)&tmp8, 1) < 0) {
return -1;
}
tmp = tmp8;
if (i2c_read(dev->bus, dev->addr, REG_INPUT+1, 1, (uint8_t*)&tmp8, 1) < 0) {
return -1;
}
tmp |= ((uint16_t)tmp)<<8;
*value = tmp & mask;
return 0;
}
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "hal/i2c_driver.h"
#define AW9523B_PIN_0 (1 << 0)
#define AW9523B_PIN_1 (1 << 1)
#define AW9523B_PIN_2 (1 << 2)
#define AW9523B_PIN_3 (1 << 3)
#define AW9523B_PIN_4 (1 << 4)
#define AW9523B_PIN_5 (1 << 5)
#define AW9523B_PIN_6 (1 << 6)
#define AW9523B_PIN_7 (1 << 7)
#define AW9523B_PIN_8 (1 << 8)
#define AW9523B_PIN_9 (1 << 9)
#define AW9523B_PIN_10 (1 << 10)
#define AW9523B_PIN_11 (1 << 11)
#define AW9523B_PIN_12 (1 << 12)
#define AW9523B_PIN_13 (1 << 13)
#define AW9523B_PIN_14 (1 << 14)
#define AW9523B_PIN_15 (1 << 15)
typedef struct {
etx_i2c_bus_t bus;
uint16_t addr;
// uint16_t interrupt; // unused, the direction config is used to enable interrupts for all input pins
uint16_t direction;
uint16_t output;
} aw9523b_t;
int aw9523b_init(aw9523b_t* dev, etx_i2c_bus_t bus, uint16_t addr);
int aw9523b_set_direction(aw9523b_t* dev, uint16_t mask, uint16_t dir);
int aw9523b_set_polarity(aw9523b_t* dev, uint16_t mask, uint16_t dir);
int aw9523b_write(aw9523b_t* dev, uint16_t mask, uint16_t value);
int aw9523b_read(aw9523b_t* dev, uint16_t mask, uint16_t* value);