Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Burns <[email protected]>
  • Loading branch information
GregBurns committed Feb 21, 2024
1 parent 1216108 commit 89d393e
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 127 deletions.
136 changes: 67 additions & 69 deletions src/dev/mcp23x17.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "per/gpio.h"
#include "per/i2c.h"

#undef SetBit

namespace daisy
{
// Adapted from https://github.com/blemasle/arduino-mcp23017
Expand Down Expand Up @@ -168,28 +166,28 @@ class Mcp23X17
{
transport.Init(config.transport_config);

//BANK = 0 : sequential register addresses
//MIRROR = 0 : use configureInterrupt
//SEQOP = 1 : sequential operation disabled, address pointer does not increment
//DISSLW = 0 : slew rate enabled
//HAEN = 0 : hardware address pin is always enabled on 23017
//ODR = 0 : open drain output
//INTPOL = 0 : interrupt active low
//BANK = 0 : sequential register addresses
//MIRROR = 0 : use configureInterrupt
//SEQOP = 1 : sequential operation disabled, address pointer does not increment
//DISSLW = 0 : slew rate enabled
//HAEN = 0 : hardware address pin is always enabled on 23017
//ODR = 0 : open drain output
//INTPOL = 0 : interrupt active low
transport.WriteReg(MCPRegister::IOCON, 0b00100000);

//enable all pull up resistors (will be effective for input pins only)
transport.WriteReg(MCPRegister::GPPU_A, 0xFF, 0xFF);
};

/**
* Controls the pins direction on a whole port at once.
*
* directions: 0 - output, 1 - input
* pullups: 0 - disabled, 1 - enabled
* inverted: 0 - false/normal, 1 - true/inverted
*
* See "3.5.1 I/O Direction register".
*/
* Controls the pins direction on a whole port at once.
*
* directions: 0 - output, 1 - input
* pullups: 0 - disabled, 1 - enabled
* inverted: 0 - false/normal, 1 - true/inverted
*
* See "3.5.1 I/O Direction register".
*/
void PortMode(MCPPort port,
uint8_t directions,
uint8_t pullups = 0xFF,
Expand All @@ -201,14 +199,14 @@ class Mcp23X17
}

/**
* Controls a single pin direction.
* Pin 0-7 for port A, 8-15 fo port B.
*
* 1 = Pin is configured as an input.
* 0 = Pin is configured as an output.
*
* See "3.5.1 I/O Direction register".
*/
* Controls a single pin direction.
* Pin 0-7 for port A, 8-15 fo port B.
*
* 1 = Pin is configured as an input.
* 0 = Pin is configured as an output.
*
* See "3.5.1 I/O Direction register".
*/
void PinMode(uint8_t pin, MCPMode mode, bool inverted)
{
MCPRegister iodirreg = MCPRegister::IODIR_A;
Expand Down Expand Up @@ -243,14 +241,14 @@ class Mcp23X17
}

/**
* Writes a single pin state.
* Pin 0-7 for port A, 8-15 for port B.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Writes a single pin state.
* Pin 0-7 for port A, 8-15 for port B.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
void WritePin(uint8_t pin, uint8_t state)
{
MCPRegister gpioreg = MCPRegister::GPIO_A;
Expand All @@ -275,14 +273,14 @@ class Mcp23X17
}

/**
* Reads a single pin state.
* Pin 0-7 for port A, 8-15 for port B.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Reads a single pin state.
* Pin 0-7 for port A, 8-15 for port B.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
uint8_t ReadPin(uint8_t pin)
{
MCPRegister gpioreg = MCPRegister::GPIO_A;
Expand All @@ -303,53 +301,53 @@ class Mcp23X17
}

/**
* Writes pins state to a whole port.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Writes pins state to a whole port.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
void WritePort(MCPPort port, uint8_t value)
{
transport.WriteReg(MCPRegister::GPIO_A + port, value);
}

/**
* Reads pins state for a whole port.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Reads pins state for a whole port.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
uint8_t ReadPort(MCPPort port)
{
return transport.ReadReg(MCPRegister::GPIO_A + port);
}

/**
* Writes pins state to both ports.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Writes pins state to both ports.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
void Write(uint16_t value)
{
transport.WriteReg(
MCPRegister::GPIO_A, LowByte(value), HighByte(value));
}

/**
* Reads pins state for both ports.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
* Reads pins state for both ports.
*
* 1 = Logic-high
* 0 = Logic-low
*
* See "3.5.10 Port register".
*/
uint16_t Read()
{
uint8_t a = ReadPort(MCPPort::A);
Expand Down
78 changes: 37 additions & 41 deletions src/hid/usb_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,51 @@ ApplicationTypeDef Appli_state = APPLICATION_IDLE;

class USBHostHandle::Impl
{
public:
Impl() {
memset(&hUsbHostHS, 0, sizeof(hUsbHostHS));
}
~Impl() {}
public:
Impl() { memset(&hUsbHostHS, 0, sizeof(hUsbHostHS)); }
~Impl() {}

Result RegisterClass(USBH_ClassTypeDef* pClass);
Result Init(USBHostHandle::Config& config);
Result Deinit();
Result Reinit();
Result Process();
Result ReEnumerate();
Result RegisterClass(USBH_ClassTypeDef* pClass);
Result Init(USBHostHandle::Config& config);
Result Deinit();
Result Reinit();
Result Process();
Result ReEnumerate();

bool GetReady();
bool GetReady();

inline Config& GetConfig() { return config_; }
inline Config& GetConfig() { return config_; }

private:
Config config_;
private:
Config config_;

/** @brief Maps ST Middleware USBH_StatusTypeDef to USBHostHandle::Result codes */
Result ConvertStatus(USBH_StatusTypeDef sta)
/** @brief Maps ST Middleware USBH_StatusTypeDef to USBHostHandle::Result codes */
Result ConvertStatus(USBH_StatusTypeDef sta)
{
if(sta != USBH_OK)
{
if(sta != USBH_OK)
{
return Result::FAIL;
}
switch(sta)
{
case USBH_OK: return Result::OK;
case USBH_BUSY: return Result::BUSY;
case USBH_NOT_SUPPORTED: return Result::NOT_SUPPORTED;
case USBH_UNRECOVERED_ERROR: return Result::UNRECOVERED_ERROR;
case USBH_ERROR_SPEED_UNKNOWN: return Result::ERROR_SPEED_UNKNOWN;
case USBH_FAIL:
default: return Result::FAIL;
}
return Result::FAIL;
}
switch(sta)
{
case USBH_OK: return Result::OK;
case USBH_BUSY: return Result::BUSY;
case USBH_NOT_SUPPORTED: return Result::NOT_SUPPORTED;
case USBH_UNRECOVERED_ERROR: return Result::UNRECOVERED_ERROR;
case USBH_ERROR_SPEED_UNKNOWN: return Result::ERROR_SPEED_UNKNOWN;
case USBH_FAIL:
default: return Result::FAIL;
}
}
};

// Global handle
static USBHostHandle::Impl usbh_impl;

static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id);
static void USBH_UserProcess(USBH_HandleTypeDef* phost, uint8_t id);

USBHostHandle::Result USBHostHandle::Impl::RegisterClass(USBH_ClassTypeDef* pClass)
USBHostHandle::Result
USBHostHandle::Impl::RegisterClass(USBH_ClassTypeDef* pClass)
{
return ConvertStatus(USBH_RegisterClass(&hUsbHostHS, pClass));
}
Expand Down Expand Up @@ -174,13 +173,12 @@ bool USBHostHandle::GetPresent()
// Shared USB IRQ Handlers are located in sys/System.cpps

// This isn't super useful for our typical code structure
static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
static void USBH_UserProcess(USBH_HandleTypeDef* phost, uint8_t id)
{
auto &conf = usbh_impl.GetConfig();
auto& conf = usbh_impl.GetConfig();
switch(id)
{
case HOST_USER_SELECT_CONFIGURATION:
break;
case HOST_USER_SELECT_CONFIGURATION: break;
case HOST_USER_CLASS_ACTIVE:
Appli_state = APPLICATION_READY;
if(conf.class_active_callback)
Expand All @@ -189,8 +187,7 @@ static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
cb(conf.userdata);
}
break;
case HOST_USER_CLASS_SELECTED:
break;
case HOST_USER_CLASS_SELECTED: break;
case HOST_USER_CONNECTION:
Appli_state = APPLICATION_START;
if(conf.connect_callback)
Expand All @@ -214,7 +211,6 @@ static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
cb(conf.userdata);
}
break;
default:
break;
default: break;
}
}
14 changes: 8 additions & 6 deletions src/hid/usb_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "hid/usb_midi.h"
#include <cassert>

extern "C" {
extern "C"
{
extern USBH_HandleTypeDef hUsbHostHS;
}

Expand Down Expand Up @@ -102,7 +103,7 @@ void MidiUsbTransport::Impl::Init(Config config)
*/
// static_assert(1u == sizeof(MidiUsbTransport::Impl::usb_handle_), "UsbHandle is not static");

config_ = config;
config_ = config;
rx_active_ = false;

if(config_.periph == Config::HOST)
Expand All @@ -128,16 +129,16 @@ void MidiUsbTransport::Impl::Init(Config config)

void MidiUsbTransport::Impl::Tx(uint8_t* buffer, size_t size)
{
int attempt_count = config_.tx_retry_count;
bool should_retry;
int attempt_count = config_.tx_retry_count;
bool should_retry;

MidiToUsb(buffer, size);
do
{
if(config_.periph == Config::HOST)
{
MIDI_ErrorTypeDef result;
result = USBH_MIDI_Transmit(pUSB_Host, tx_buffer_, tx_ptr_);
result = USBH_MIDI_Transmit(pUSB_Host, tx_buffer_, tx_ptr_);
should_retry = (result == MIDI_BUSY) && attempt_count--;
}
else
Expand All @@ -147,7 +148,8 @@ void MidiUsbTransport::Impl::Tx(uint8_t* buffer, size_t size)
result = usb_handle_.TransmitExternal(tx_buffer_, tx_ptr_);
else
result = usb_handle_.TransmitInternal(tx_buffer_, tx_ptr_);
should_retry = (result == UsbHandle::Result::ERR) && attempt_count--;
should_retry
= (result == UsbHandle::Result::ERR) && attempt_count--;
}


Expand Down
1 change: 0 additions & 1 deletion src/hid/usb_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define __DSY_MIDIUSBTRANSPORT_H__

#include "hid/usb.h"
#include "hid/usb_host.h"
#include "sys/system.h"
#include "util/ringbuffer.h"

Expand Down
Loading

0 comments on commit 89d393e

Please sign in to comment.