From 7fba51649afff45c4b72d634a563e05be85d3093 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 1 May 2021 13:17:10 +1000 Subject: [PATCH] Cleanup user functions --- source/Core/BSP/BSP_PD.h | 1 - source/Core/BSP/MHP30/Power.cpp | 1 + source/Core/BSP/MHP30/fusb_user.cpp | 42 +----------------------- source/Core/BSP/Miniware/fusb_user.cpp | 2 +- source/Core/BSP/Pine64/fusb_user.cpp | 2 +- source/Core/Drivers/FUSB302/fusb302b.cpp | 28 +++++++++++++++- source/Core/Drivers/FUSB302/fusb_user.h | 30 +++++++++++++---- source/Core/Drivers/FUSB302/fusbpd.h | 3 -- source/Core/Drivers/FUSB302/int_n.cpp | 5 ++- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/source/Core/BSP/BSP_PD.h b/source/Core/BSP/BSP_PD.h index f2c97802..a0dde7c2 100644 --- a/source/Core/BSP/BSP_PD.h +++ b/source/Core/BSP/BSP_PD.h @@ -8,6 +8,5 @@ #ifndef USER_BSP_PD_H_ #define USER_BSP_PD_H_ #include "BSP.h" -bool getFUS302IRQLow(); // Return true if the IRQ line is still held low #endif /* USER_BSP_PD_H_ */ diff --git a/source/Core/BSP/MHP30/Power.cpp b/source/Core/BSP/MHP30/Power.cpp index 913b9cf3..95dd26e3 100644 --- a/source/Core/BSP/MHP30/Power.cpp +++ b/source/Core/BSP/MHP30/Power.cpp @@ -4,6 +4,7 @@ #include "Pins.h" #include "QC3.h" #include "Settings.h" +#include "fusb_user.h" #include "fusbpd.h" #include "int_n.h" #include "policy_engine.h" diff --git a/source/Core/BSP/MHP30/fusb_user.cpp b/source/Core/BSP/MHP30/fusb_user.cpp index af170720..bddf5a72 100644 --- a/source/Core/BSP/MHP30/fusb_user.cpp +++ b/source/Core/BSP/MHP30/fusb_user.cpp @@ -6,52 +6,12 @@ #include "Setup.h" #include "fusb302b.h" #include "fusb_user.h" -/* - * Read a single byte from the FUSB302B - * - * cfg: The FUSB302B to communicate with - * addr: The memory address from which to read - * - * Returns the value read from addr. - */ -uint8_t fusb_read_byte(uint8_t addr) { - uint8_t data[1]; - if (!FRToSI2C::Mem_Read(FUSB302B_ADDR, addr, (uint8_t *)data, 1)) { - return 0; - } - return data[0]; -} -/* - * Read multiple bytes from the FUSB302B - * - * cfg: The FUSB302B to communicate with - * addr: The memory address from which to read - * size: The number of bytes to read - * buf: The buffer into which data will be read - */ bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) { return FRToSI2C::Mem_Read(FUSB302B_ADDR, addr, buf, size); } -/* - * Write a single byte to the FUSB302B - * - * cfg: The FUSB302B to communicate with - * addr: The memory address to which we will write - * byte: The value to write - */ -bool fusb_write_byte(uint8_t addr, uint8_t byte) { return FRToSI2C::Mem_Write(FUSB302B_ADDR, addr, (uint8_t *)&byte, 1); } - -/* - * Write multiple bytes to the FUSB302B - * - * cfg: The FUSB302B to communicate with - * addr: The memory address to which we will write - * size: The number of bytes to write - * buf: The buffer to write - */ bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { return FRToSI2C::Mem_Write(FUSB302B_ADDR, addr, (uint8_t *)buf, size); } -uint8_t fusb302_detect() { +bool fusb302_detect() { // Probe the I2C bus for its address return FRToSI2C::probe(FUSB302B_ADDR); } diff --git a/source/Core/BSP/Miniware/fusb_user.cpp b/source/Core/BSP/Miniware/fusb_user.cpp index 5ae87423..9d4640c1 100644 --- a/source/Core/BSP/Miniware/fusb_user.cpp +++ b/source/Core/BSP/Miniware/fusb_user.cpp @@ -50,7 +50,7 @@ bool fusb_write_byte(uint8_t addr, uint8_t byte) { return I2CBB::Mem_Write(FUSB3 */ bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size); } -uint8_t fusb302_detect() { +bool fusb302_detect() { // Probe the I2C bus for its address return I2CBB::probe(FUSB302B_ADDR); } diff --git a/source/Core/BSP/Pine64/fusb_user.cpp b/source/Core/BSP/Pine64/fusb_user.cpp index bc62bc62..3c5b6a0b 100644 --- a/source/Core/BSP/Pine64/fusb_user.cpp +++ b/source/Core/BSP/Pine64/fusb_user.cpp @@ -50,7 +50,7 @@ bool fusb_write_byte(uint8_t addr, uint8_t byte) { return FRToSI2C::Mem_Write(FU */ bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { return FRToSI2C::Mem_Write(FUSB302B_ADDR, addr, (uint8_t *)buf, size); } -uint8_t fusb302_detect() { +bool fusb302_detect() { // Probe the I2C bus for its address return FRToSI2C::probe(FUSB302B_ADDR); } diff --git a/source/Core/Drivers/FUSB302/fusb302b.cpp b/source/Core/Drivers/FUSB302/fusb302b.cpp index c0ecf735..83bab9c7 100644 --- a/source/Core/Drivers/FUSB302/fusb302b.cpp +++ b/source/Core/Drivers/FUSB302/fusb302b.cpp @@ -21,7 +21,9 @@ #include "fusb_user.h" #include "int_n.h" #include -void fusb_send_message(const union pd_msg *msg) { +uint8_t fusb_read_byte(uint8_t addr); +bool fusb_write_byte(uint8_t addr, uint8_t byte); +void fusb_send_message(const union pd_msg *msg) { /* Token sequences for the FUSB302B */ static uint8_t sop_seq[5] = {FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM}; @@ -161,3 +163,27 @@ bool fusb_read_id() { return false; return true; } +/* + * Read a single byte from the FUSB302B + * + * cfg: The FUSB302B to communicate with + * addr: The memory address from which to read + * + * Returns the value read from addr. + */ +uint8_t fusb_read_byte(uint8_t addr) { + uint8_t data[1]; + if (!fusb_read_buf(addr, 1, (uint8_t *)data)) { + return 0; + } + return data[0]; +} + +/* + * Write a single byte to the FUSB302B + * + * cfg: The FUSB302B to communicate with + * addr: The memory address to which we will write + * byte: The value to write + */ +bool fusb_write_byte(uint8_t addr, uint8_t byte) { return fusb_write_buf(addr, 1, (uint8_t *)&byte); } diff --git a/source/Core/Drivers/FUSB302/fusb_user.h b/source/Core/Drivers/FUSB302/fusb_user.h index 9a81c611..55a27ebf 100644 --- a/source/Core/Drivers/FUSB302/fusb_user.h +++ b/source/Core/Drivers/FUSB302/fusb_user.h @@ -19,11 +19,29 @@ #define PDB_FUSB_USER_H #include -uint8_t fusb_read_byte(uint8_t addr); -bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf); -bool fusb_write_byte(uint8_t addr, uint8_t byte); -bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf); -uint8_t fusb302_detect(); -void setupFUSBIRQ(); +/* + * Read multiple bytes from the FUSB302B + * + * cfg: The FUSB302B to communicate with + * addr: The memory address from which to read + * size: The number of bytes to read + * buf: The buffer into which data will be read + */ +bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf); +/* + * Write multiple bytes to the FUSB302B + * + * cfg: The FUSB302B to communicate with + * addr: The memory address to which we will write + * size: The number of bytes to write + * buf: The buffer to write + */ +bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf); +// Used to poll for the device existing on the I2C bus. This should return non-zero if the device is responding on the bus +bool fusb302_detect(); +// Once this is called IRQ's should be enabled and routed to the IRQ handler thread +void setupFUSBIRQ(); +// This should return true if the IRQ line for the FUSB302 is still held low +bool getFUS302IRQLow(); #endif /* PDB_FUSB302B_H */ diff --git a/source/Core/Drivers/FUSB302/fusbpd.h b/source/Core/Drivers/FUSB302/fusbpd.h index 353bb338..1f3a80fb 100644 --- a/source/Core/Drivers/FUSB302/fusbpd.h +++ b/source/Core/Drivers/FUSB302/fusbpd.h @@ -11,8 +11,5 @@ extern struct pdb_config pdb_config_data; #include -// returns 1 if the FUSB302 is on the I2C bus -uint8_t fusb302_detect(); - void fusb302_start_processing(); #endif /* DRIVERS_FUSB302_FUSBPD_H_ */ diff --git a/source/Core/Drivers/FUSB302/int_n.cpp b/source/Core/Drivers/FUSB302/int_n.cpp index 7cd06fac..7c00b651 100644 --- a/source/Core/Drivers/FUSB302/int_n.cpp +++ b/source/Core/Drivers/FUSB302/int_n.cpp @@ -16,12 +16,11 @@ */ #include "int_n.h" -#include "BSP.h" -#include "BSP_PD.h" +#include "Defines.h" #include "fusb302b.h" +#include "fusb_user.h" #include "fusbpd.h" #include "policy_engine.h" - #include "task.h" #include #include