diff --git a/.travis.yml b/.travis.yml index 2a46dfc5..3dc25114 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,9 @@ env: - PLATFORMIO_CI_SRC=examples/board_qc - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal - 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/scale - PLATFORMIO_CI_SRC=examples/HID/SRWS1 diff --git a/UHS2_gpio.cpp b/UHS2_gpio.cpp index 04814f46..3957f15d 100644 --- a/UHS2_gpio.cpp +++ b/UHS2_gpio.cpp @@ -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) */ void UHS2_GPIO::digitalWrite(uint8_t pin, uint8_t val) { - if(pin > 7) - return; - uint8_t nValue = m_pUsb->gpioRdOutput(); - uint8_t nMask = 1 << pin; - nValue &= (~nMask); - if(val) - nValue |= (nMask); - m_pUsb->gpioWr(nValue); + if(pin > 7) + return; + uint8_t nValue = m_pUsb->gpioRdOutput(); + uint8_t nMask = 1 << pin; + nValue &= (~nMask); + if(val) + nValue |= (nMask); + m_pUsb->gpioWr(nValue); } /** @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) */ int UHS2_GPIO::digitalRead(uint8_t pin) { - if(pin > 7) - return -1; - uint8_t nMask = 1 << pin; - uint8_t nValue = m_pUsb->gpioRd(); - return ((nValue & nMask)?1:0); + if(pin > 7) + return -1; + uint8_t nMask = 1 << pin; + uint8_t nValue = m_pUsb->gpioRd(); + return ((nValue & nMask)?1:0); } /** @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 */ int UHS2_GPIO::digitalReadOutput(uint8_t pin) { - if(pin > 7) - return -1; - uint8_t nMask = 1 << pin; - uint8_t nValue = m_pUsb->gpioRdOutput(); - return ((nValue & nMask)?1:0); + if(pin > 7) + return -1; + uint8_t nMask = 1 << pin; + uint8_t nValue = m_pUsb->gpioRdOutput(); + return ((nValue & nMask)?1:0); } diff --git a/UHS2_gpio.h b/UHS2_gpio.h index 06f5e587..498b99b8 100644 --- a/UHS2_gpio.h +++ b/UHS2_gpio.h @@ -29,16 +29,15 @@ UHS2_GPIO implements "wiring" style GPIO access. Implemented by Brian Walton bri #include "Usb.h" -class UHS2_GPIO -{ - public: +class UHS2_GPIO { +public: UHS2_GPIO(USB *pUsb); void digitalWrite(uint8_t pin, uint8_t val); int digitalRead(uint8_t pin); int digitalReadOutput(uint8_t pin); - private: +private: USB* m_pUsb; }; diff --git a/examples/GPIO/Blink/Blink.ino b/examples/GPIO/Blink/Blink.ino index 1b785fd3..d7bc594a 100644 --- a/examples/GPIO/Blink/Blink.ino +++ b/examples/GPIO/Blink/Blink.ino @@ -11,8 +11,8 @@ #define OUTPUT_PIN 0 -USB Usb; //Create an UHS2 interface object -UHS2_GPIO GPIO(&Usb); //Create a GPIO object +USB Usb; // Create an UHS2 interface object +UHS2_GPIO GPIO(&Usb); // Create a GPIO object void setup() { @@ -30,11 +30,11 @@ void setup() 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); - nValue = (nValue?0:1); + nValue = (nValue ? 0 : 1); 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); } diff --git a/examples/GPIO/Blink_LowLevel/Blink_LowLevel.ino b/examples/GPIO/Blink_LowLevel/Blink_LowLevel.ino index ca1dca31..119b4780 100644 --- a/examples/GPIO/Blink_LowLevel/Blink_LowLevel.ino +++ b/examples/GPIO/Blink_LowLevel/Blink_LowLevel.ino @@ -28,13 +28,13 @@ void setup() 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 nValue = ((nGPO & 0x01) == 0x01)?0:1; - nGPO &= 0xFE; //clear bit 0 + uint8_t nValue = ((nGPO & 0x01) == 0x01) ? 0 : 1; + nGPO &= 0xFE; // Clear bit 0 nGPO |= nValue; 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); } diff --git a/examples/GPIO/Input/Input.ino b/examples/GPIO/Input/Input.ino index f7dd9c7d..7306df93 100644 --- a/examples/GPIO/Input/Input.ino +++ b/examples/GPIO/Input/Input.ino @@ -11,8 +11,8 @@ #define INPUT_PIN 0 #define OUTPUT_PIN 0 -USB Usb; //Create an UHS2 interface object -UHS2_GPIO GPIO(&Usb); //Create a GPIO object +USB Usb; // Create an UHS2 interface object +UHS2_GPIO GPIO(&Usb); // Create a GPIO object void setup() { @@ -30,9 +30,9 @@ void setup() 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); - nValue = (nValue?0:1); + nValue = (nValue ? LOW : HIGH); GPIO.digitalWrite(OUTPUT_PIN, nValue); }