mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-25 01:05:21 +03:00
PCF8574 Basic Driver
This commit is contained in:
parent
da298c63c1
commit
d85693cd98
9 changed files with 149 additions and 1 deletions
|
@ -45,6 +45,7 @@ COMMON_SRC = \
|
||||||
drivers/exti.c \
|
drivers/exti.c \
|
||||||
drivers/io.c \
|
drivers/io.c \
|
||||||
drivers/io_pca9685.c \
|
drivers/io_pca9685.c \
|
||||||
|
drivers/io_pcf8574.c \
|
||||||
drivers/irlock.c \
|
drivers/irlock.c \
|
||||||
drivers/light_led.c \
|
drivers/light_led.c \
|
||||||
drivers/osd.c \
|
drivers/osd.c \
|
||||||
|
|
|
@ -73,5 +73,6 @@ typedef enum {
|
||||||
DEBUG_IRLOCK,
|
DEBUG_IRLOCK,
|
||||||
DEBUG_CD,
|
DEBUG_CD,
|
||||||
DEBUG_KALMAN,
|
DEBUG_KALMAN,
|
||||||
|
DEBUG_PCF8574,
|
||||||
DEBUG_COUNT
|
DEBUG_COUNT
|
||||||
} debugType_e;
|
} debugType_e;
|
||||||
|
|
|
@ -145,6 +145,7 @@ typedef enum {
|
||||||
DEVHW_UG2864, // I2C OLED display
|
DEVHW_UG2864, // I2C OLED display
|
||||||
DEVHW_SDCARD, // Generic SD-Card
|
DEVHW_SDCARD, // Generic SD-Card
|
||||||
DEVHW_IRLOCK, // IR-Lock visual positioning hardware
|
DEVHW_IRLOCK, // IR-Lock visual positioning hardware
|
||||||
|
DEVHW_PCF8574, // 8-bit I/O expander
|
||||||
} devHardwareType_e;
|
} devHardwareType_e;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
90
src/main/drivers/io_pcf8574.c
Normal file
90
src/main/drivers/io_pcf8574.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* This file is part of INAV.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms
|
||||||
|
* of the GNU General Public License Version 3, as described below:
|
||||||
|
*
|
||||||
|
* This file is free software: you may copy, redistribute and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This file 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "drivers/bus.h"
|
||||||
|
#include "drivers/io_pcf8574.h"
|
||||||
|
#include "drivers/time.h"
|
||||||
|
#include "build/debug.h"
|
||||||
|
|
||||||
|
#ifdef USE_PCF8574
|
||||||
|
|
||||||
|
#define PCF8574_WRITE_ADDRESS 0x40
|
||||||
|
#define PCF8574_READ_ADDRESS 0x41
|
||||||
|
|
||||||
|
static busDevice_t *busDev;
|
||||||
|
|
||||||
|
static bool deviceDetect(busDevice_t *busDev)
|
||||||
|
{
|
||||||
|
for (int retry = 0; retry < 5; retry++)
|
||||||
|
{
|
||||||
|
uint8_t sig;
|
||||||
|
|
||||||
|
delay(150);
|
||||||
|
|
||||||
|
bool ack = busRead(busDev, 0x00, &sig);
|
||||||
|
if (ack)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pcf8574Init(void)
|
||||||
|
{
|
||||||
|
busDev = busDeviceInit(BUSTYPE_I2C, DEVHW_PCF8574, 0, 0);
|
||||||
|
if (busDev == NULL)
|
||||||
|
{
|
||||||
|
DEBUG_SET(DEBUG_PCF8574, 0, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deviceDetect(busDev))
|
||||||
|
{
|
||||||
|
DEBUG_SET(DEBUG_PCF8574, 0, 2);
|
||||||
|
busDeviceDeInit(busDev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pcf8574Write(0x00); //Set all ports to OFF
|
||||||
|
delay(25);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pcf8574Write(uint8_t data)
|
||||||
|
{
|
||||||
|
busWrite(busDev, PCF8574_WRITE_ADDRESS, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t pcf8574Read(void)
|
||||||
|
{
|
||||||
|
uint8_t data;
|
||||||
|
busRead(busDev, PCF8574_READ_ADDRESS, &data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
29
src/main/drivers/io_pcf8574.h
Normal file
29
src/main/drivers/io_pcf8574.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* This file is part of INAV.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms
|
||||||
|
* of the GNU General Public License Version 3, as described below:
|
||||||
|
*
|
||||||
|
* This file is free software: you may copy, redistribute and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This file 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
bool pcf8574Init(void);
|
||||||
|
void pcf8574Write(uint8_t data);
|
||||||
|
uint8_t pcf8574Read(void);
|
|
@ -83,6 +83,7 @@
|
||||||
#include "msc/emfat_file.h"
|
#include "msc/emfat_file.h"
|
||||||
#endif
|
#endif
|
||||||
#include "drivers/sdcard/sdcard.h"
|
#include "drivers/sdcard/sdcard.h"
|
||||||
|
#include "drivers/io_pcf8574.h"
|
||||||
|
|
||||||
#include "fc/cli.h"
|
#include "fc/cli.h"
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
|
@ -674,6 +675,11 @@ void init(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_PCF8574
|
||||||
|
bool pcfActive = pcf8574Init();
|
||||||
|
DEBUG_SET(DEBUG_PCF8574, 1, pcfActive);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Considering that the persistent reset reason is only used during init
|
// Considering that the persistent reset reason is only used during init
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ tables:
|
||||||
"FLOW", "SBUS", "FPORT", "ALWAYS", "SAG_COMP_VOLTAGE",
|
"FLOW", "SBUS", "FPORT", "ALWAYS", "SAG_COMP_VOLTAGE",
|
||||||
"VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC", "ITERM_RELAX",
|
"VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC", "ITERM_RELAX",
|
||||||
"ERPM", "RPM_FILTER", "RPM_FREQ", "NAV_YAW", "DYNAMIC_FILTER", "DYNAMIC_FILTER_FREQUENCY",
|
"ERPM", "RPM_FILTER", "RPM_FREQ", "NAV_YAW", "DYNAMIC_FILTER", "DYNAMIC_FILTER_FREQUENCY",
|
||||||
"IRLOCK", "CD", "KALMAN"]
|
"IRLOCK", "CD", "KALMAN", "PCF8574"]
|
||||||
- name: async_mode
|
- name: async_mode
|
||||||
values: ["NONE", "GYRO", "ALL"]
|
values: ["NONE", "GYRO", "ALL"]
|
||||||
- name: aux_operator
|
- name: aux_operator
|
||||||
|
|
|
@ -121,6 +121,9 @@
|
||||||
#define USE_D_BOOST
|
#define USE_D_BOOST
|
||||||
#define USE_ANTIGRAVITY
|
#define USE_ANTIGRAVITY
|
||||||
|
|
||||||
|
#define USE_I2C_IO_EXPANDER
|
||||||
|
#define USE_PCF8574
|
||||||
|
|
||||||
#else // FLASH_SIZE < 256
|
#else // FLASH_SIZE < 256
|
||||||
#define LOG_LEVEL_MAXIMUM LOG_LEVEL_ERROR
|
#define LOG_LEVEL_MAXIMUM LOG_LEVEL_ERROR
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -353,4 +353,21 @@
|
||||||
BUSDEV_REGISTER_I2C(busdev_irlock, DEVHW_IRLOCK, IRLOCK_I2C_BUS, 0x54, NONE, DEVFLAGS_USE_RAW_REGISTERS);
|
BUSDEV_REGISTER_I2C(busdev_irlock, DEVHW_IRLOCK, IRLOCK_I2C_BUS, 0x54, NONE, DEVFLAGS_USE_RAW_REGISTERS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_I2C) && defined(USE_PCF8574)
|
||||||
|
|
||||||
|
#if !defined(PCF8574_I2C_BUS) && defined(EXTERNAL_I2C_BUS)
|
||||||
|
#define PCF8574_I2C_BUS EXTERNAL_I2C_BUS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(PCF8574_I2C_BUS) && defined(DEFAULT_I2C_BUS)
|
||||||
|
#define PCF8574_I2C_BUS DEFAULT_I2C_BUS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(PCF8574_I2C_BUS)
|
||||||
|
#define PCF8574_I2C_BUS BUS_I2C1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BUSDEV_REGISTER_I2C(busdev_pcf8574, DEVHW_PCF8574, PCF8574_I2C_BUS, 0x20, NONE, DEVFLAGS_NONE, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // USE_TARGET_HARDWARE_DESCRIPTORS
|
#endif // USE_TARGET_HARDWARE_DESCRIPTORS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue