Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Language: Cpp
BasedOnStyle: Google
IndentWidth: 2
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Attach
DerivePointerAlignment: false
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
20 changes: 20 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ name: Arduino Library CI
on: [pull_request, push, repository_dispatch]

jobs:
clang-format:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: adafruit/ci-arduino
path: ci

- name: pre-install
run: bash ci/actions_install.sh

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

build:
needs: clang-format
runs-on: ubuntu-latest

steps:
Expand Down
17 changes: 11 additions & 6 deletions ProTrinketMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ License along with ProTrinketMouse. If not, see
*/

#include "ProTrinketMouse.h"
#include "ProTrinketMouseC.h"
#include "cmdline_defs.h"

#include <avr/interrupt.h>
#include <stdint.h>
#include <util/delay.h>

#include "ProTrinketMouseC.h"
#include "cmdline_defs.h"

// create an instance that the user can use
Trinket_Mouse TrinketMouse;

Expand All @@ -37,15 +38,17 @@ Trinket_Mouse::Trinket_Mouse() {
}

// starts the USB driver, causes re-enumeration
void Trinket_Mouse::begin() { usbBegin(); }
void Trinket_Mouse::begin() {
usbBegin();
}

// makes a mouse movement, must be called at least once every 10ms, even if no
// movement

void Trinket_Mouse::move(signed char x, signed char y, signed char wheel,
uint8_t buttonMask) {
signed char *signed_ptr =
(signed char *)report_buffer; // this converts signed to unsigned
signed char* signed_ptr =
(signed char*)report_buffer; // this converts signed to unsigned

// format the report structure
signed_ptr[1] = x;
Expand All @@ -57,4 +60,6 @@ void Trinket_Mouse::move(signed char x, signed char y, signed char wheel,
}

// checks if USB is connected, 0 if not connected
char Trinket_Mouse::isConnected() { return usb_hasCommed; }
char Trinket_Mouse::isConnected() {
return usb_hasCommed;
}
4 changes: 2 additions & 2 deletions ProTrinketMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ extern "C" {
#define MOUSEBTN_MIDDLE_MASK 0x04

class Trinket_Mouse {
private:
public:
private:
public:
Trinket_Mouse(); // empty constructor, ignore me
void begin(); // starts the USB driver, causes re-enumeration
void move(signed char x, signed char y, signed char wheel,
Expand Down
54 changes: 29 additions & 25 deletions ProTrinketMouseC.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ License along with ProTrinketMouse. If not, see
*/

#include "ProTrinketMouseC.h"
#include "cmdline_defs.h"
#include "usbconfig.h"
#include "usbdrv/usbdrv.h"

#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
#include <stdint.h>
#include <util/delay.h>

#include "cmdline_defs.h"
#include "usbconfig.h"
#include "usbdrv/usbdrv.h"

uint8_t report_buffer[4];
char usb_hasCommed = 0;
uint8_t idle_rate = 500 / 4; // see HID1_11.pdf sect 7.2.4
Expand All @@ -50,14 +52,16 @@ void usbBegin() {
sei();
}

void usbPollWrapper() { usbPoll(); }
void usbPollWrapper() {
usbPoll();
}

void usbReportSend() {
// perform usb background tasks until the report can be sent, then send it
while (1) {
usbPoll(); // this needs to be called at least once every 10 ms
if (usbInterruptIsReady()) {
usbSetInterrupt((uint8_t *)report_buffer, 4); // send
usbSetInterrupt((uint8_t*)report_buffer, 4); // send
break;

// see http://vusb.wikidot.com/driver-api
Expand Down Expand Up @@ -106,31 +110,31 @@ usbMsgLen_t usbFunctionSetup(uint8_t data[8]) {
usb_hasCommed = 1;

// see HID1_11.pdf sect 7.2 and http://vusb.wikidot.com/driver-api
usbRequest_t *rq = (void *)data;
usbRequest_t* rq = (void*)data;

if ((rq->bmRequestType & USBRQ_TYPE_MASK) != USBRQ_TYPE_CLASS)
return 0; // ignore request if it's not a class specific request

// see HID1_11.pdf sect 7.2
switch (rq->bRequest) {
case USBRQ_HID_GET_IDLE:
usbMsgPtr = &idle_rate; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_IDLE:
idle_rate = rq->wValue.bytes[1]; // read in idle rate
return 0; // send nothing
case USBRQ_HID_GET_PROTOCOL:
usbMsgPtr = &protocol_version; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_PROTOCOL:
protocol_version = rq->wValue.bytes[1];
return 0; // send nothing
case USBRQ_HID_GET_REPORT:
usbMsgPtr = (uint8_t *)report_buffer; // send the report data
return 3;
case USBRQ_HID_SET_REPORT:
return 0; // send nothing, mouses don't do this
default: // do not understand data, ignore
return 0; // send nothing
case USBRQ_HID_GET_IDLE:
usbMsgPtr = &idle_rate; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_IDLE:
idle_rate = rq->wValue.bytes[1]; // read in idle rate
return 0; // send nothing
case USBRQ_HID_GET_PROTOCOL:
usbMsgPtr = &protocol_version; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_PROTOCOL:
protocol_version = rq->wValue.bytes[1];
return 0; // send nothing
case USBRQ_HID_GET_REPORT:
usbMsgPtr = (uint8_t*)report_buffer; // send the report data
return 3;
case USBRQ_HID_SET_REPORT:
return 0; // send nothing, mouses don't do this
default: // do not understand data, ignore
return 0; // send nothing
}
}
20 changes: 10 additions & 10 deletions usbconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ License along with ProTrinketMouse. If not, see
/* define this macro to 1 if you want the function usbMeasureFrameLength()
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
*/
#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__) || \
#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__) || \
defined(__AVR_ATtiny25__)
#ifndef __ASSEMBLER__
#include <avr/interrupt.h> // for sei()
extern void calibrateOscillator(void);
#endif
#define USB_RESET_HOOK(resetStarts) \
if (!resetStarts) { \
cli(); \
calibrateOscillator(); \
sei(); \
#define USB_RESET_HOOK(resetStarts) \
if (!resetStarts) { \
cli(); \
calibrateOscillator(); \
sei(); \
}
#endif

Expand Down Expand Up @@ -275,8 +275,8 @@ extern void calibrateOscillator(void);
* obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
* details.
*/
#define USB_CFG_DEVICE_NAME \
'P', 'r', 'o', ' ', 'T', 'r', 'i', 'n', 'k', 'e', 't', ' ', 'M', 'o', 'u', \
#define USB_CFG_DEVICE_NAME \
'P', 'r', 'o', ' ', 'T', 'r', 'i', 'n', 'k', 'e', 't', ' ', 'M', 'o', 'u', \
's', 'e'
#define USB_CFG_DEVICE_NAME_LEN 17
/* Same as above for the device name. If you don't want a device name, undefine
Expand All @@ -292,7 +292,7 @@ extern void calibrateOscillator(void);
* to fine tune control over USB descriptors such as the string descriptor
* for the serial number.
*/
#define USB_CFG_DEVICE_CLASS \
#define USB_CFG_DEVICE_CLASS \
0x00 // 0x00 means "check the interface class instead"
#define USB_CFG_DEVICE_SUBCLASS 0x00
/* See USB specification if you want to conform to an existing device class.
Expand All @@ -314,7 +314,7 @@ extern void calibrateOscillator(void);
* Don't forget to keep the array and this define in sync!
*/

//#define USB_PUBLIC static
// #define USB_PUBLIC static
/* Use the define above if you #include usbdrv.c instead of linking against it.
* This technique saves a couple of bytes in flash memory.
*/
Expand Down
2 changes: 1 addition & 1 deletion usbdrv/oddebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void printHex(uchar c) {
uartPutc(hexAscii(c));
}

void odDebug(uchar prefix, uchar *data, uchar len) {
void odDebug(uchar prefix, uchar* data, uchar len) {
printHex(prefix);
uartPutc(':');
while (len--) {
Expand Down
4 changes: 2 additions & 2 deletions usbdrv/oddebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ the output and a memory block to dump in hex ('data' and 'len').
#define uchar unsigned char
#endif

#if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device \
#if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device \
*/
#warning "Debugging disabled because device has no UART"
#undef DEBUG_LEVEL
Expand All @@ -61,7 +61,7 @@ the output and a memory block to dump in hex ('data' and 'len').
/* ------------------------------------------------------------------------- */

#if DEBUG_LEVEL > 0
extern void odDebug(uchar prefix, uchar *data, uchar len);
extern void odDebug(uchar prefix, uchar* data, uchar len);

/* Try to find our control registers; ATMEL likes to rename these */

Expand Down
Loading