Fixes coding style.

Adds examples to travis.
This commit is contained in:
riban 2018-10-15 08:18:16 +01:00
parent 401f4991e9
commit 1d7dbd640b
6 changed files with 37 additions and 35 deletions

View file

@ -39,6 +39,9 @@ env:
- PLATFORMIO_CI_SRC=examples/board_qc - PLATFORMIO_CI_SRC=examples/board_qc
- PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal
- PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback
- PLATFORMIO_CI_SRC=examples/GPIO/Blink
- PLATFORMIO_CI_SRC=examples/GPIO/Blink_LowLevel
- PLATFORMIO_CI_SRC=examples/GPIO/Input
- PLATFORMIO_CI_SRC=examples/HID/le3dp - PLATFORMIO_CI_SRC=examples/HID/le3dp
- PLATFORMIO_CI_SRC=examples/HID/scale - PLATFORMIO_CI_SRC=examples/HID/scale
- PLATFORMIO_CI_SRC=examples/HID/SRWS1 - PLATFORMIO_CI_SRC=examples/HID/SRWS1

View file

@ -38,14 +38,14 @@ UHS2_GPIO::UHS2_GPIO(USB *pUsb) : m_pUsb(pUsb)
* @param val Value to set the pin to (zero value will clear output, non-zero value will assert output) * @param val Value to set the pin to (zero value will clear output, non-zero value will assert output)
*/ */
void UHS2_GPIO::digitalWrite(uint8_t pin, uint8_t val) { void UHS2_GPIO::digitalWrite(uint8_t pin, uint8_t val) {
if(pin > 7) if(pin > 7)
return; return;
uint8_t nValue = m_pUsb->gpioRdOutput(); uint8_t nValue = m_pUsb->gpioRdOutput();
uint8_t nMask = 1 << pin; uint8_t nMask = 1 << pin;
nValue &= (~nMask); nValue &= (~nMask);
if(val) if(val)
nValue |= (nMask); nValue |= (nMask);
m_pUsb->gpioWr(nValue); m_pUsb->gpioWr(nValue);
} }
/** @brief Read the value from a GPIO input pin /** @brief Read the value from a GPIO input pin
@ -53,11 +53,11 @@ void UHS2_GPIO::digitalWrite(uint8_t pin, uint8_t val) {
* @retval int Value of GPIO input (-1 on fail) * @retval int Value of GPIO input (-1 on fail)
*/ */
int UHS2_GPIO::digitalRead(uint8_t pin) { int UHS2_GPIO::digitalRead(uint8_t pin) {
if(pin > 7) if(pin > 7)
return -1; return -1;
uint8_t nMask = 1 << pin; uint8_t nMask = 1 << pin;
uint8_t nValue = m_pUsb->gpioRd(); uint8_t nValue = m_pUsb->gpioRd();
return ((nValue & nMask)?1:0); return ((nValue & nMask)?1:0);
} }
/** @brief Read the value from a GPIO output pin /** @brief Read the value from a GPIO output pin
@ -66,9 +66,9 @@ int UHS2_GPIO::digitalRead(uint8_t pin) {
* @note Value of MAX3421E output register, i.e. what the device has been set to, not the physical value on the pin * @note Value of MAX3421E output register, i.e. what the device has been set to, not the physical value on the pin
*/ */
int UHS2_GPIO::digitalReadOutput(uint8_t pin) { int UHS2_GPIO::digitalReadOutput(uint8_t pin) {
if(pin > 7) if(pin > 7)
return -1; return -1;
uint8_t nMask = 1 << pin; uint8_t nMask = 1 << pin;
uint8_t nValue = m_pUsb->gpioRdOutput(); uint8_t nValue = m_pUsb->gpioRdOutput();
return ((nValue & nMask)?1:0); return ((nValue & nMask)?1:0);
} }

View file

@ -29,16 +29,15 @@ UHS2_GPIO implements "wiring" style GPIO access. Implemented by Brian Walton bri
#include "Usb.h" #include "Usb.h"
class UHS2_GPIO class UHS2_GPIO {
{ public:
public:
UHS2_GPIO(USB *pUsb); UHS2_GPIO(USB *pUsb);
void digitalWrite(uint8_t pin, uint8_t val); void digitalWrite(uint8_t pin, uint8_t val);
int digitalRead(uint8_t pin); int digitalRead(uint8_t pin);
int digitalReadOutput(uint8_t pin); int digitalReadOutput(uint8_t pin);
private: private:
USB* m_pUsb; USB* m_pUsb;
}; };

View file

@ -11,8 +11,8 @@
#define OUTPUT_PIN 0 #define OUTPUT_PIN 0
USB Usb; //Create an UHS2 interface object USB Usb; // Create an UHS2 interface object
UHS2_GPIO GPIO(&Usb); //Create a GPIO object UHS2_GPIO GPIO(&Usb); // Create a GPIO object
void setup() void setup()
{ {
@ -30,11 +30,11 @@ void setup()
void loop() void loop()
{ {
//Get the current output value, toggle then wait half a second // Get the current output value, toggle then wait half a second
int nValue = GPIO.digitalReadOutput(OUTPUT_PIN); int nValue = GPIO.digitalReadOutput(OUTPUT_PIN);
nValue = (nValue?0:1); nValue = (nValue ? 0 : 1);
GPIO.digitalWrite(OUTPUT_PIN, nValue); GPIO.digitalWrite(OUTPUT_PIN, nValue);
Serial.print(nValue?"+":"."); //Debug to show what the output should be doing Serial.print(nValue ? "+" : "."); // Debug to show what the output should be doing
delay(500); delay(500);
} }

View file

@ -28,13 +28,13 @@ void setup()
void loop() void loop()
{ {
//Get the current output value, toggle then wait half a second // Get the current output value, toggle then wait half a second
uint8_t nGPO = Usb.gpioRdOutput(); uint8_t nGPO = Usb.gpioRdOutput();
uint8_t nValue = ((nGPO & 0x01) == 0x01)?0:1; uint8_t nValue = ((nGPO & 0x01) == 0x01) ? 0 : 1;
nGPO &= 0xFE; //clear bit 0 nGPO &= 0xFE; // Clear bit 0
nGPO |= nValue; nGPO |= nValue;
Usb.gpioWr(nGPO); Usb.gpioWr(nGPO);
Serial.print(nValue?"+":"."); //Debug to show what the output should be doing Serial.print(nValue ? "+" : "."); // Debug to show what the output should be doing
delay(500); delay(500);
} }

View file

@ -11,8 +11,8 @@
#define INPUT_PIN 0 #define INPUT_PIN 0
#define OUTPUT_PIN 0 #define OUTPUT_PIN 0
USB Usb; //Create an UHS2 interface object USB Usb; // Create an UHS2 interface object
UHS2_GPIO GPIO(&Usb); //Create a GPIO object UHS2_GPIO GPIO(&Usb); // Create a GPIO object
void setup() void setup()
{ {
@ -30,9 +30,9 @@ void setup()
void loop() void loop()
{ {
//Get the value of input, set value of output // Get the value of input, set value of output
int nValue = GPIO.digitalRead(INPUT_PIN); int nValue = GPIO.digitalRead(INPUT_PIN);
nValue = (nValue?0:1); nValue = (nValue ? LOW : HIGH);
GPIO.digitalWrite(OUTPUT_PIN, nValue); GPIO.digitalWrite(OUTPUT_PIN, nValue);
} }