1
0
forked from me/IronOS

Cleanup user functions

This commit is contained in:
Ben V. Brown
2021-05-01 13:17:10 +10:00
parent 2ca2f9084f
commit 7fba51649a
9 changed files with 57 additions and 57 deletions

View File

@@ -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_ */

View File

@@ -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"

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -21,6 +21,8 @@
#include "fusb_user.h"
#include "int_n.h"
#include <pd.h>
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 */
@@ -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); }

View File

@@ -19,11 +19,29 @@
#define PDB_FUSB_USER_H
#include <stdint.h>
uint8_t fusb_read_byte(uint8_t addr);
/*
* 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);
bool fusb_write_byte(uint8_t addr, uint8_t byte);
/*
* 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);
uint8_t fusb302_detect();
// 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 */

View File

@@ -11,8 +11,5 @@
extern struct pdb_config pdb_config_data;
#include <stdint.h>
// returns 1 if the FUSB302 is on the I2C bus
uint8_t fusb302_detect();
void fusb302_start_processing();
#endif /* DRIVERS_FUSB302_FUSBPD_H_ */

View File

@@ -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 <pd.h>
#include <string.h>