Skip to content

Commit

Permalink
small fixes to framework to be able to compile with sdcc 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Timm Korte committed May 31, 2016
1 parent f021290 commit fa45904
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
17 changes: 14 additions & 3 deletions apps/shiftbrite/shiftbrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ BIT radioBlinkActive = 0;
uint8 radioLastActivity;
uint8 radioBlinkStart;

// This is initialized to be equal to param_input_bits, but restricted to be within 1..16.
uint8 input_bits;

// The number of hex characters it takes to express a color.
// 1-4 input bits = 1 char; 5-8 input bits = 2 chars; etc.
uint8 hex_chars_per_color;

// amount to shift to create the output
int8 shift;

// converts 0-9, a-f, or A-F into the corresponding hex value
uint8 hexCharToByte(char c)
{
Expand Down Expand Up @@ -124,9 +134,6 @@ void shiftbriteProcessByte(char c)
{
static char rgb[12]; // big enough to hold 4 hex digits times three colors
static uint8 i = 0;
static const uint8 input_bits = restrictRange(param_input_bits,1,16); // allow up to 16 bits = 4 hex digits
static const uint8 hex_chars_per_color = ((input_bits-1) >> 2) + 1; // 1-4 bits = 1; 5-8 bits = 2; etc.
static const int8 shift = 10 - input_bits; // amount to shift to create the output

if(c == '\r' || c == '\n')
{
Expand Down Expand Up @@ -193,6 +200,10 @@ void shiftbriteService()

void shiftbriteInit()
{
input_bits = restrictRange(param_input_bits,1,16); // allow up to 16 bits = 4 hex digits
hex_chars_per_color = ((input_bits-1) >> 2) + 1;
shift = 10 - input_bits;

SHIFTBRITE_DISABLE = 1; // disable shiftbrites until a valid color is sent
SHIFTBRITE_CLOCK = 0; // clock low
SHIFTBRITE_LATCH = 0; // prevent unintended latching
Expand Down
2 changes: 1 addition & 1 deletion libraries/include/usb_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ uint8 usbComRxReceiveByte(void);
* usbComRxAvailable().
*
* See also usbComRxReceiveByte(). */
void usbComRxReceive(const uint8 XDATA * buffer, uint8 size);
void usbComRxReceive(uint8 XDATA * buffer, uint8 size);

/*! \return The number of bytes available in the TX buffers.
*
Expand Down
18 changes: 10 additions & 8 deletions libraries/include/usb_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ typedef struct HID_MOUSE_IN_REPORT
* device's joystick interface to the host. */
typedef struct HID_JOYSTICK_IN_REPORT
{
int8 x; /*!< Joystick X axis position. Valid values are from -127 to 127. */
int8 y; /*!< Joystick Y axis position. Valid values are from -127 to 127. */
int8 z; /*!< Joystick Z axis position. Valid values are from -127 to 127. */
int8 rx; /*!< Joystick's rotation about the X axis. Valid values are from -127 to 127. */
int8 ry; /*!< Joystick's rotation about the Y axis. Valid values are from -127 to 127. */
int8 rz; /*!< Joystick's rotation about the Z axis. Valid values are from -127 to 127. */

uint16 buttons; /*!< A bit map that specifies which buttons are pressed. */
int16 x; /*!< Joystick X axis position. Valid values are from -32767 to 32767. */
int16 y; /*!< Joystick Y axis position. Valid values are from -32767 to 32767. */
int16 z; /*!< Joystick Z axis position. Valid values are from -32767 to 32767. */
int16 rx; /*!< Joystick's rotation about the X axis. Valid values are from -32767 to 32767. */
int16 ry; /*!< Joystick's rotation about the Y axis. Valid values are from -32767 to 32767. */
int16 rz; /*!< Joystick's rotation about the Z axis. Valid values are from -32767 to 32767. */
int16 slider; /*!< Joystick's slider position. Valid values are from -32767 to 32767. */
int16 dial; /*!< Joystick's dial position. Valid values are from -32767 to 32767. */

uint32 buttons; /*!< A bit map that specifies which buttons are pressed. */
} HID_JOYSTICK_IN_REPORT;

/*! Contains \b output data received by the \b keyboard interface from the host.
Expand Down
8 changes: 4 additions & 4 deletions libraries/src/radio_mac/radio_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ISR(RF, 0)
// We were not reading data from the radio fast enough, so there was
// a RX overflow. This should not happen. Report it as an error.
radioRxOverflowOccurred = 1;
RFIF = ~0x40;
RFIF = (uint8)(~0x40);

// The radio module is probably now in the RX_OVERFLOW state where it can not
// receive packets. The way to get out of this state is:
Expand Down Expand Up @@ -191,17 +191,17 @@ void radioMacEvent(uint8 event)
// We want to do it before restarting the radio (to avoid accidentally missing
// an event) but we want to do it as long as possible AFTER turning off the
// radio.
RFIF = ~0x30; // Clear IRQ_DONE and IRQ_TIMEOUT if they are set.
RFIF = (uint8)(~0x30); // Clear IRQ_DONE and IRQ_TIMEOUT if they are set.

/** Start up the radio in the new state which was decided above. **/
switch(radioMacState)
{
case RADIO_MAC_STATE_RX:
DMAARM |= (1<<DMA_CHANNEL_RADIO); // Arm DMA channel.
DMAARM = (1<<DMA_CHANNEL_RADIO); // Arm DMA channel.
RFST = SRX; // Switch radio to RX.
break;
case RADIO_MAC_STATE_TX:
DMAARM |= (1<<DMA_CHANNEL_RADIO); // Arm DMA channel.
DMAARM = (1<<DMA_CHANNEL_RADIO); // Arm DMA channel.
RFST = STX; // Switch radio to TX.
break;
case RADIO_MAC_STATE_IDLE:
Expand Down
22 changes: 12 additions & 10 deletions libraries/src/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

extern uint8 CODE usbConfigurationDescriptor[];

void usbStandardDeviceRequestHandler();
static void usbStandardDeviceRequestHandler();

#define CONTROL_TRANSFER_STATE_NONE 0
#define CONTROL_TRANSFER_STATE_WRITE 1
Expand Down Expand Up @@ -223,6 +223,12 @@ void usbPoll()

USBINDEX = 0; // Select EP0 again because the functions above might have changed USBINDEX.

// Modify the count so that we don't send more data than the host requested.
if(controlTransferBytesLeft > usbSetupPacket.wLength)
{
controlTransferBytesLeft = usbSetupPacket.wLength;
}

// Prepare for the first transaction after the SETUP packet.
if (controlTransferState == CONTROL_TRANSFER_STATE_NONE)
{
Expand Down Expand Up @@ -336,7 +342,11 @@ static void usbStandardDeviceRequestHandler()
{
if ((usbSetupPacket.wValue & 0xFF) >= usbStringDescriptorCount)
{
// Invalid string index.
// This is either an invalid string index or it is 0xEE,
// which is defined by Microsoft OS Descriptors 1.0.
// This library provides no features for handling such requests,
// but we call the user's callback in case they want to.
usbCallbackClassDescriptorHandler();
return;
}

Expand All @@ -358,14 +368,6 @@ static void usbStandardDeviceRequestHandler()
}
}

// Modify the count so that we don't send more data than the host requested.
// We MUST use the local variable wLength instead of usbSetupPacket.wLength because
// USB_SETUP_PACKET may have been over-written by the serial number handler.
if(controlTransferBytesLeft > usbSetupPacket.wLength)
{
controlTransferBytesLeft = usbSetupPacket.wLength;
}

controlTransferState = CONTROL_TRANSFER_STATE_READ;
return;
}
Expand Down
38 changes: 23 additions & 15 deletions libraries/src/usb_hid/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

/* HID Library Configuration **************************************************/

#define HID_IN_PACKET_SIZE 8
#define HID_IN_KEYBOARD_PACKET_SIZE 8
#define HID_IN_MOUSE_PACKET_SIZE 4
#define HID_IN_JOYSTICK_PACKET_SIZE 20

#define HID_KEYBOARD_INTERFACE_NUMBER 0
#define HID_MOUSE_INTERFACE_NUMBER 1
#define HID_JOYSTICK_INTERFACE_NUMBER 2
Expand Down Expand Up @@ -52,6 +55,7 @@
#define HID_USAGE_MIN 0x19
#define HID_USAGE_MAX 0x29
#define HID_LOGICAL_MIN 0x15
#define HID_LOGICAL_MIN_2 0x16 // 2-byte data
#define HID_LOGICAL_MAX 0x25
#define HID_LOGICAL_MAX_2 0x26 // 2-byte data
#define HID_INPUT 0x81
Expand All @@ -74,6 +78,8 @@
#define HID_USAGE_RX 0x33
#define HID_USAGE_RY 0x34
#define HID_USAGE_RZ 0x35
#define HID_USAGE_SLIDER 0x36
#define HID_USAGE_DIAL 0x37
#define HID_USAGE_WHEEL 0x38

// HID Report Collection Types from HID 1.12 6.2.2.6
Expand Down Expand Up @@ -213,25 +219,27 @@ uint8 CODE joystickReportDescriptor[]
HID_USAGE, HID_USAGE_POINTER,
HID_COLLECTION, HID_COLLECTION_PHYSICAL,

HID_REPORT_COUNT, 6, // 6 Axes (X, Y, Z, Rx, Ry, Rz)
HID_REPORT_SIZE, 8,
HID_REPORT_COUNT, 8, // 8 Axes (X, Y, Z, Rx, Ry, Rz, Slider, Dial)
HID_REPORT_SIZE, 16,
HID_USAGE, HID_USAGE_X,
HID_USAGE, HID_USAGE_Y,
HID_USAGE, HID_USAGE_Z,
HID_USAGE, HID_USAGE_RX,
HID_USAGE, HID_USAGE_RY,
HID_USAGE, HID_USAGE_RZ,
HID_LOGICAL_MIN, -127,
HID_LOGICAL_MAX, 127,
HID_USAGE, HID_USAGE_SLIDER,
HID_USAGE, HID_USAGE_DIAL,
HID_LOGICAL_MIN_2, 0x01, 0x80, // -32767
HID_LOGICAL_MAX_2, 0xFF, 0x7F, // 32767
HID_INPUT, HID_ITEM_VARIABLE,

HID_END_COLLECTION,

HID_REPORT_COUNT, 16, // 16 Joystick Buttons
HID_REPORT_COUNT, 32, // 32 Joystick Buttons
HID_REPORT_SIZE, 1,
HID_USAGE_PAGE, HID_USAGE_PAGE_BUTTONS,
HID_USAGE_MIN, 1,
HID_USAGE_MAX, 16,
HID_USAGE_MAX, 32,
HID_LOGICAL_MIN, 0,
HID_LOGICAL_MAX, 1,
HID_INPUT, HID_ITEM_VARIABLE,
Expand Down Expand Up @@ -291,7 +299,7 @@ CODE struct CONFIG1 {
USB_DESCRIPTOR_TYPE_ENDPOINT,
USB_ENDPOINT_ADDRESS_IN | HID_KEYBOARD_ENDPOINT, // bEndpointAddress
USB_TRANSFER_TYPE_INTERRUPT, // bmAttributes
HID_IN_PACKET_SIZE, // wMaxPacketSize
HID_IN_KEYBOARD_PACKET_SIZE, // wMaxPacketSize
10, // bInterval
},
{ // Mouse Interface
Expand Down Expand Up @@ -319,7 +327,7 @@ CODE struct CONFIG1 {
USB_DESCRIPTOR_TYPE_ENDPOINT,
USB_ENDPOINT_ADDRESS_IN | HID_MOUSE_ENDPOINT, // bEndpointAddress
USB_TRANSFER_TYPE_INTERRUPT, // bmAttributes
HID_IN_PACKET_SIZE, // wMaxPacketSize
HID_IN_MOUSE_PACKET_SIZE, // wMaxPacketSize
10, // bInterval
},
{ // Joystick Interface
Expand Down Expand Up @@ -347,7 +355,7 @@ CODE struct CONFIG1 {
USB_DESCRIPTOR_TYPE_ENDPOINT,
USB_ENDPOINT_ADDRESS_IN | HID_JOYSTICK_ENDPOINT, // bEndpointAddress
USB_TRANSFER_TYPE_INTERRUPT, // bmAttributes
HID_IN_PACKET_SIZE, // wMaxPacketSize
HID_IN_JOYSTICK_PACKET_SIZE, // wMaxPacketSize
10, // bInterval
},
};
Expand All @@ -366,7 +374,7 @@ uint16 CODE * CODE usbStringDescriptors[] = { languages, manufacturer, product,
HID_KEYBOARD_OUT_REPORT XDATA usbHidKeyboardOutput = {0};
HID_KEYBOARD_IN_REPORT XDATA usbHidKeyboardInput = {0, 0, {0}};
HID_MOUSE_IN_REPORT XDATA usbHidMouseInput = {0, 0, 0, 0};
HID_JOYSTICK_IN_REPORT XDATA usbHidJoystickInput = {0, 0, 0, 0, 0, 0, 0};
HID_JOYSTICK_IN_REPORT XDATA usbHidJoystickInput = {0, 0, 0, 0, 0, 0, 0, 0, 0};

BIT usbHidKeyboardInputUpdated = 0;
BIT usbHidMouseInputUpdated = 0;
Expand All @@ -383,9 +391,9 @@ BIT hidMouseProtocol = HID_PROTOCOL_REPORT;

void usbCallbackInitEndpoints(void)
{
usbInitEndpointIn(HID_KEYBOARD_ENDPOINT, HID_IN_PACKET_SIZE);
usbInitEndpointIn(HID_MOUSE_ENDPOINT, HID_IN_PACKET_SIZE);
usbInitEndpointIn(HID_JOYSTICK_ENDPOINT, HID_IN_PACKET_SIZE);
usbInitEndpointIn(HID_KEYBOARD_ENDPOINT, HID_IN_KEYBOARD_PACKET_SIZE);
usbInitEndpointIn(HID_MOUSE_ENDPOINT, HID_IN_MOUSE_PACKET_SIZE);
usbInitEndpointIn(HID_JOYSTICK_ENDPOINT, HID_IN_JOYSTICK_PACKET_SIZE);
}

// Implements all the control transfers that are required by Appendix G of HID 1.11.
Expand Down Expand Up @@ -653,7 +661,7 @@ uint8 CODE hidKeyCode[128] =
KEY_PERIOD, // 0x3E >
KEY_SLASH, // 0x3F ?

KEY_3, // 0x40 @
KEY_2, // 0x40 @
KEY_A, // 0x41 A
KEY_B, // 0x42 B
KEY_C, // 0x43 C
Expand Down

0 comments on commit fa45904

Please sign in to comment.