Skip to content

Commit 0f486ba

Browse files
committed
style corrections and warning removal on multiple files. WIP on USB code
Also addressing Issue #29 with respect to PROGMEM data warnings
1 parent 68c6ac2 commit 0f486ba

File tree

11 files changed

+2054
-1022
lines changed

11 files changed

+2054
-1022
lines changed

cores/xmega/CDC.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
/* Copyright (c) 2011, Peter Barrett
42
**
53
** Permission to use, copy, modify, and/or distribute this software for
@@ -23,6 +21,21 @@
2321
#if defined(USBCON)
2422
#ifdef CDC_ENABLED
2523

24+
#if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
25+
#define PROGMEM_ORIG PROGMEM
26+
#else // PROGMEM workaround
27+
28+
// to avoid the bogus "initialized variables" warning
29+
#ifdef PROGMEM
30+
#undef PROGMEM
31+
#endif // PROGMEM re-define
32+
33+
#define PROGMEM __attribute__((section(".progmem.cdc")))
34+
#define PROGMEM_ORIG __attribute__((__progmem__))
35+
36+
#endif // check for GNUC >= or < 4.6
37+
38+
2639
typedef struct
2740
{
2841
u32 dwDTERate;

cores/xmega/HID.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@
2323
#if defined(USBCON)
2424
#ifdef HID_ENABLED
2525

26+
#if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
27+
#define PROGMEM_ORIG PROGMEM
28+
#else // PROGMEM workaround
29+
30+
// to avoid the bogus "initialized variables" warning
31+
#ifdef PROGMEM
32+
#undef PROGMEM
33+
#endif // PROGMEM re-define
34+
35+
#define PROGMEM __attribute__((section(".progmem.hid")))
36+
#define PROGMEM_ORIG __attribute__((__progmem__))
37+
38+
#endif // check for GNUC >= or < 4.6
39+
40+
2641
//#define RAWHID_ENABLED
2742

2843
// Singletons for mouse and keyboard

cores/xmega/HardwareSerial.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@
3636
#include "wiring_private.h"
3737
#include "HardwareSerial.h"
3838

39+
#if __GNUC__ > 4 || (__GNUC__ > 4 && __GNUC_MINOR__ >= 6)
40+
#define PROGMEM_ORIG PROGMEM
41+
#else // PROGMEM workaround
42+
43+
// to avoid the bogus "initialized variables" warning
44+
#ifdef PROGMEM
45+
#undef PROGMEM
46+
#endif // PROGMEM re-define
47+
48+
#define PROGMEM __attribute__((section(".progmem.hardwareserial")))
49+
#define PROGMEM_ORIG __attribute__((__progmem__))
50+
51+
#endif // check for GNUC >= or < 4.6
52+
53+
3954
#ifndef SERIAL_0_PORT_NAME
4055
#define SERIAL_0_PORT_NAME PORTD
4156
#define SERIAL_0_USART_NAME USARTD0

cores/xmega/IPAddress.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
// A class to make it easier to handle and pass around IP addresses
2626

27-
class IPAddress : public Printable {
27+
class IPAddress : public Printable
28+
{
2829
private:
2930
uint8_t _address[4]; // IPv4 address
3031
// Access the raw byte array containing the address. Because this returns a pointer
@@ -42,8 +43,19 @@ class IPAddress : public Printable {
4243

4344
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
4445
// to a four-byte uint8_t array is expected
45-
operator uint32_t() { return *((uint32_t*)_address); };
46-
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
46+
operator uint32_t()
47+
{
48+
register const uint32_t *p1 = (const uint32_t *)(const void *)_address;
49+
return *p1;
50+
};
51+
bool operator==(const IPAddress& addr)
52+
{
53+
register const uint32_t *p1 = (const uint32_t*)_address;
54+
register const uint32_t *p2 = (const uint32_t*)(addr._address);
55+
56+
return *p1 == *p2;
57+
};
58+
4759
bool operator==(const uint8_t* addr);
4860

4961
// Overloaded index operator to allow getting and setting individual octets of the address

cores/xmega/Print.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,32 @@ size_t Print::printFloat(double number, uint8_t digits)
262262

263263
return n;
264264
}
265+
266+
// things that I added
267+
268+
int Print::printf(const char *pszFormat, ...) /*__attribute__ ((format(printf, 2, 3)))*/ // added API for 'printf' since it has been suggested...
269+
{
270+
va_list va;
271+
int cbOut;
272+
273+
va_start(va, pszFormat);
274+
275+
cbOut = vsnprintf(NULL, 0, pszFormat, va);
276+
277+
if(cbOut > 0)
278+
{
279+
char *p1 = (char *)malloc(cbOut + 2);
280+
281+
if(p1)
282+
{
283+
cbOut = vsnprintf(p1, cbOut + 1, pszFormat, va);
284+
print(p1);
285+
free(p1);
286+
}
287+
}
288+
289+
va_end(va);
290+
291+
return cbOut;
292+
}
293+

cores/xmega/Print.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ class Print
4646
void clearWriteError() { setWriteError(0); }
4747

4848
virtual size_t write(uint8_t) = 0;
49-
size_t write(const char *str) {
49+
size_t write(const char *str)
50+
{
5051
if (str == NULL) return 0;
5152
return write((const uint8_t *)str, strlen(str));
5253
}
5354
virtual size_t write(const uint8_t *buffer, size_t size);
54-
size_t write(const char *buffer, size_t size) {
55+
size_t write(const char *buffer, size_t size)
56+
{
5557
return write((const uint8_t *)buffer, size);
5658
}
59+
60+
int printf(const char *pszFormat, ...) __attribute__ ((format(printf, 2, 3))); // added API for 'printf' since it has been suggested...
5761

5862
size_t print(const __FlashStringHelper *);
5963
size_t print(const String &);

0 commit comments

Comments
 (0)