Merge pull request #207 from henrygab/fix_compile_warnings3

Improve build script & fix more warnings
This commit is contained in:
Ha Thach 2020-08-10 14:12:13 +07:00 committed by GitHub
commit fd40287bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 256 additions and 168 deletions

View file

@ -49,7 +49,7 @@ jobs:
arduino-cli core update-index --additional-urls $BSP_URL
arduino-cli core install arduino:samd --additional-urls $BSP_URL
arduino-cli core install adafruit:samd --additional-urls $BSP_URL
# Repalce release BSP with our code
# Replace release BSP with our code
BSP_VERSION=`eval ls $HOME/$BSP_PATH`
rm -r $HOME/$BSP_PATH/*
ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION
@ -57,3 +57,7 @@ jobs:
- name: Build examples
run: python3 extras/build_all.py ${{ matrix.arduino-platform }}
# How to mark this as allowed-to-fail?
- name: Build examples (-Wall)
run: python3 extras/build_all.py --all_warnings --warnings_do_not_cause_job_failure

View file

@ -248,7 +248,7 @@ class SERCOM
uint32_t getFreqRef(void) { return freqRef; };
#else
// The equivalent SAMD21 dummy functions...
void setClockSource(__attribute__((unused)) int8_t idx, __attribute__((unused)) SercomClockSource src, __attribute__((unused)) bool core) { };
void setClockSource(int8_t idx, SercomClockSource src, bool core) { (void)idx; (void)src; (void)core; };
SercomClockSource getClockSource(void) { return SERCOM_CLOCK_SOURCE_FCPU; };
uint32_t getFreqRef(void) { return F_CPU; };
#endif

View file

@ -250,8 +250,9 @@ void detachInterrupt(uint32_t pin)
* External Interrupt Controller NVIC Interrupt Handler
*/
#if defined(__SAMD51__)
void InterruptHandler(uint32_t i)
void InterruptHandler(uint32_t unused_i)
{
(void)unused_i;
// Calling the routine directly from -here- takes about 1us
// Depending on where you are in the list it will take longer

View file

@ -165,18 +165,18 @@ uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples)
{
uint32_t i;
int32_t diff;
uint32_t diffCrnt;
uint32_t diffCrnt = 0;
uint32_t maxDiff = 0;
for (i = 0; i < numSamples; i++)
{
diff = pIn[i] - pOut[i];
diffCrnt = (diff > 0) ? diff : -diff;
diff = pIn[i] - pOut[i];
diffCrnt = (uint32_t)( (diff > 0) ? diff : -diff );
if(diffCrnt > maxDiff)
{
maxDiff = diffCrnt;
}
if(diffCrnt > maxDiff)
{
maxDiff = diffCrnt;
}
}
return(maxDiff);
@ -194,18 +194,18 @@ uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t * pOut, uint32_t numSamples)
{
uint32_t i;
int32_t diff;
uint32_t diffCrnt;
uint32_t diffCrnt = 0;
uint32_t maxDiff = 0;
for (i = 0; i < numSamples; i++)
{
diff = pIn[i] - pOut[i];
diffCrnt = (diff > 0) ? diff : -diff;
diff = pIn[i] - pOut[i];
diffCrnt = (uint32_t)( (diff > 0) ? diff : -diff );
if(diffCrnt > maxDiff)
{
maxDiff = diffCrnt;
}
if(diffCrnt > maxDiff)
{
maxDiff = diffCrnt;
}
}
return(maxDiff);

View file

@ -3,27 +3,42 @@ import glob
import sys
import subprocess
import time
import argparse
FQBN_PREFIX='adafruit:samd:adafruit_'
parser = argparse.ArgumentParser(
description='python wrapper for adafruit arduino CI workflows',
allow_abbrev=False
)
parser.add_argument(
'--all_warnings', '--Wall',
action='store_true',
help='build with all warnings enabled (`--warnings all`)',
)
parser.add_argument(
'--warnings_do_not_cause_job_failure',
action='store_true',
help='failed builds will be listed as failed, but not cause job to exit with an error status',
)
parser.add_argument(
'build_boards',
metavar='board',
nargs='*',
help='list of boards to be built -- Note that the fqbn is created by prepending "{}"'.format(FQBN_PREFIX),
default= [ 'metro_m0', 'metro_m4', 'circuitplayground_m0' ]
)
args = parser.parse_args()
all_warnings = False
exit_status = 0
success_count = 0
fail_count = 0
skip_count = 0
build_format = '| {:22} | {:30} | {:9} '
build_separator = '-' * 80
default_boards = [ 'metro_m0', 'metro_m4', 'circuitplayground_m0']
build_boards = []
# build all variants if input not existed
if len(sys.argv) > 1:
build_boards.append(sys.argv[1])
else:
build_boards = default_boards
def errorOutputFilter(line):
def errorOutputFilter(line: str):
if len(line) == 0:
return False
if line.isspace(): # Note: empty string does not match here!
@ -31,9 +46,8 @@ def errorOutputFilter(line):
# TODO: additional items to remove?
return True
def build_examples(variant):
global exit_status, success_count, fail_count, skip_count, build_format, build_separator
def build_examples(variant: str):
global args, exit_status, success_count, fail_count, skip_count, build_format, build_separator
print('\n')
print(build_separator)
@ -42,7 +56,7 @@ def build_examples(variant):
print((build_format + '| {:6} |').format('Library', 'Example', 'Result', 'Time'))
print(build_separator)
fqbn = "adafruit:samd:adafruit_{}".format(variant)
fqbn = "{}{}".format(FQBN_PREFIX, variant)
for sketch in glob.iglob('libraries/**/*.ino', recursive=True):
start_time = time.monotonic()
@ -58,14 +72,14 @@ def build_examples(variant):
# TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
# preferably, would use Python logging handler to get both distinct outputs and one merged output
# for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
if all_warnings:
if args.all_warnings:
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
build_result = subprocess.run("arduino-cli compile --warnings default --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# get stderr into a form where len(warningLines) indicates a true warning was output to stderr
warningLines = [];
if all_warnings and build_result.stderr:
if args.all_warnings and build_result.stderr:
tmpWarningLines = build_result.stderr.decode("utf-8").splitlines()
warningLines = list(filter(errorOutputFilter, (tmpWarningLines)))
@ -74,7 +88,8 @@ def build_examples(variant):
success = "\033[31mfailed\033[0m "
fail_count += 1
elif len(warningLines) != 0:
exit_status = -1
if not args.warnings_do_not_cause_job_failure:
exit_status = -1
success = "\033[31mwarnings\033[0m "
fail_count += 1
else:
@ -98,7 +113,7 @@ def build_examples(variant):
build_time = time.monotonic()
for board in build_boards:
for board in args.build_boards:
build_examples(board)
print(build_separator)

View file

@ -17,6 +17,7 @@ volatile bool transfer_is_done = false; // Done yet?
// Callback for end-of-DMA-transfer
void dma_callback(Adafruit_ZeroDMA *dma) {
(void)dma; // avoid compiler warning about unused function parameter
transfer_is_done = true;
}

View file

@ -19,6 +19,7 @@ volatile bool transfer_is_done = false; // Done yet?
// Callback for end-of-DMA-transfer
void dma_callback(Adafruit_ZeroDMA *dma) {
(void)dma; // avoid compiler warning about unused parameter
transfer_is_done = true;
}

View file

@ -33,6 +33,7 @@ volatile bool transfer_is_done = true; // Done yet?
// Callback for end-of-DMA-transfer
void dma_callback(Adafruit_ZeroDMA *dma) {
(void)dma; // avoid compiler warning about unused parameter
transfer_is_done = true;
}

View file

@ -149,7 +149,7 @@ class SPIClass {
#else
// On SAMD21, this compiles to nothing, so user code doesn't need to
// check and conditionally compile lines for different architectures.
void setClockSource(__attribute__((unused)) SercomClockSource clk) { };
void setClockSource(SercomClockSource clk) { (void)clk; };
#endif // end __SAMD51__
private:

View file

@ -174,6 +174,7 @@ static inline void resetTC (Tc* TCx)
static void _initISR(Tc *tc, uint8_t channel, uint32_t id, IRQn_Type irqn, uint8_t gcmForTimer, uint8_t intEnableBit)
{
(void)id;
// Select GCLK0 as timer/counter input clock source
#if defined(__SAMD51__)
int idx = gcmForTimer; // see datasheet Table 14-9
@ -265,6 +266,7 @@ static void initISR(timer16_Sequence_t timer)
static void finISR(timer16_Sequence_t timer)
{
(void)timer;
#if defined (_useTimer1)
// Disable the match channel interrupt request
TC_FOR_TIMER1->COUNT16.INTENCLR.reg = INTENCLR_BIT_FOR_TIMER_1;

View file

@ -37,7 +37,7 @@ void setup(void)
while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
SERIAL_PORT_MONITOR.println("\r\nADK demo start");
if (usb.Init() == -1)
if (usb.Init() == (uint32_t)-1)
SERIAL_PORT_MONITOR.println("OSC did not start.");
delay(20);

View file

@ -83,8 +83,7 @@ void setup()
{
SerialDebug.begin( 115200 );
SerialDebug.println("USB Host Keyboard Controller Program started");
if (usb.Init() == -1)
if (usb.Init() == (uint32_t)-1)
SerialDebug.println("USB Host did not start.");
SerialDebug.println("USB Host started");

View file

@ -91,7 +91,7 @@ void setup()
SerialDebug.begin( 115200 );
SerialDebug.println("USB Host Mouse Controller Program started");
if (usb.Init() == -1)
if (usb.Init() == (uint32_t)-1)
SerialDebug.println("USB Host did not start.");
SerialDebug.println("USB Host started");

View file

@ -59,8 +59,8 @@ void setup()
SerialDebug.println("Starting USB Descriptor test");
SerialDebug.println("Initializing USB");
if (usb.Init() == -1)
SerialDebug.println("USBhost did not start.");
if (usb.Init() == (uint32_t)-1)
SerialDebug.println("USBhost did not start.");
delay( 20 );
@ -161,6 +161,7 @@ byte getdevdescr( byte addr, byte &num_conf )
void printhubdescr(uint8_t *descrptr, uint8_t addr)
{
(void)addr;
HubDescriptor *pHub = (HubDescriptor*) descrptr;
uint8_t len = *((uint8_t*)descrptr);
@ -209,10 +210,11 @@ byte getconfdescr( byte addr, byte conf )
{
uint8_t buf[ BUFSIZE ];
uint8_t* buf_ptr = buf;
byte rcode;
byte rcode; // FIXME -- code does not actually check return code (no error handling!)
byte descr_length;
byte descr_type;
uint16_t total_length;
// FIXME -- no check of return code from usb.getConfDescr()
rcode = usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
LOBYTE( total_length ) = buf[ 2 ];
HIBYTE( total_length ) = buf[ 3 ];
@ -220,6 +222,7 @@ byte getconfdescr( byte addr, byte conf )
printProgStr(Conf_Trunc_str);
total_length = sizeof(buf);
}
// FIXME -- no check of return code from usb.getConfDescr()
rcode = usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
while( buf_ptr < buf + total_length ) { //parsing descriptors
descr_length = *( buf_ptr );

View file

@ -59,15 +59,15 @@ class ConfigDescParser : public USBReadParser {
uint32_t ifaceNumber; // Interface number
uint32_t ifaceAltSet; // Interface alternate settings
bool UseOr;
bool UseOr;
bool ParseDescriptor(uint8_t **pp, uint32_t *pcntdn);
void PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc);
public:
void SetOR(void) {
UseOr = true;
}
void SetOR(void) {
UseOr = true;
}
ConfigDescParser(UsbConfigXtracter *xtractor);
virtual void Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t &offset);
};
@ -98,8 +98,19 @@ void ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::Parse(const uin
compare masks for them. When the match is found, calls EndpointXtract passing buffer containing endpoint descriptor */
template <const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor(uint8_t **pp, uint32_t *pcntdn) {
USB_CONFIGURATION_DESCRIPTOR* ucd = reinterpret_cast<USB_CONFIGURATION_DESCRIPTOR*>(varBuffer);
USB_INTERFACE_DESCRIPTOR* uid = reinterpret_cast<USB_INTERFACE_DESCRIPTOR*>(varBuffer);
USB_CONFIGURATION_DESCRIPTOR* ucd = reinterpret_cast<USB_CONFIGURATION_DESCRIPTOR*>(varBuffer);
USB_INTERFACE_DESCRIPTOR* uid = reinterpret_cast<USB_INTERFACE_DESCRIPTOR*>(varBuffer);
#pragma GCC diagnostic push // Available since GCC 4.6.4
/*
* FIXME -- Enabled and review all `-Wimplicit-fallthrough` messages
* This code has multiple switch statements that "fall through" to the
* next case -- but it's not always clear if this is intentional or not.
* Review and commenting of code, and reducing cyclomatic complexity
* are highly recommended....
*/
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
switch(stateParseDescr) {
case 0:
theBuffer.valueSize = 2;
@ -112,7 +123,7 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
dscrType = *((uint8_t*)theBuffer.pValue + 1);
stateParseDescr = 2;
case 2:
// This is a sort of hack. Assuming that two bytes are all ready in the buffer
// This is a sort of hack. Assuming that two bytes are all ready in the buffer
// the pointer is positioned two bytes ahead in order for the rest of descriptor
// to be read right after the size and the type fields.
// This should be used carefully. varBuffer should be used directly to handle data
@ -120,14 +131,14 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
theBuffer.pValue = varBuffer + 2;
stateParseDescr = 3;
case 3:
switch(dscrType) {
case USB_DESCRIPTOR_INTERFACE:
isGoodInterface = false;
case USB_DESCRIPTOR_CONFIGURATION:
theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2;
break;
case USB_DESCRIPTOR_ENDPOINT:
theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2;
switch(dscrType) {
case USB_DESCRIPTOR_INTERFACE:
isGoodInterface = false;
case USB_DESCRIPTOR_CONFIGURATION:
theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2;
break;
case USB_DESCRIPTOR_ENDPOINT:
theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2;
break;
case HID_DESCRIPTOR_HID:
theBuffer.valueSize = dscrLen - 2;
@ -136,37 +147,37 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
valParser.Initialize(&theBuffer);
stateParseDescr = 4;
case 4:
switch(dscrType) {
switch(dscrType) {
case USB_DESCRIPTOR_CONFIGURATION:
if(!valParser.Parse(pp, pcntdn))
return false;
confValue = ucd->bConfigurationValue;
if(!valParser.Parse(pp, pcntdn))
return false;
confValue = ucd->bConfigurationValue;
break;
case USB_DESCRIPTOR_INTERFACE:
if(!valParser.Parse(pp, pcntdn))
return false;
if((MASK & CP_MASK_COMPARE_CLASS) && uid->bInterfaceClass != CLASS_ID)
break;
if((MASK & CP_MASK_COMPARE_SUBCLASS) && uid->bInterfaceSubClass != SUBCLASS_ID)
break;
if(UseOr) {
if((!((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol)))
break;
} else {
if((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol != PROTOCOL_ID)
break;
}
isGoodInterface = true;
ifaceNumber = uid->bInterfaceNumber;
ifaceAltSet = uid->bAlternateSetting;
protoValue = uid->bInterfaceProtocol;
break;
case USB_DESCRIPTOR_ENDPOINT:
if(!valParser.Parse(pp, pcntdn))
return false;
if(isGoodInterface)
if(theXtractor)
theXtractor->EndpointXtract(confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer);
if(!valParser.Parse(pp, pcntdn))
return false;
if((MASK & CP_MASK_COMPARE_CLASS) && uid->bInterfaceClass != CLASS_ID)
break;
if((MASK & CP_MASK_COMPARE_SUBCLASS) && uid->bInterfaceSubClass != SUBCLASS_ID)
break;
if(UseOr) {
if((!((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol)))
break;
} else {
if((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol != PROTOCOL_ID)
break;
}
isGoodInterface = true;
ifaceNumber = uid->bInterfaceNumber;
ifaceAltSet = uid->bAlternateSetting;
protoValue = uid->bInterfaceProtocol;
break;
case USB_DESCRIPTOR_ENDPOINT:
if(!valParser.Parse(pp, pcntdn))
return false;
if(isGoodInterface)
if(theXtractor)
theXtractor->EndpointXtract(confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer);
break;
//case HID_DESCRIPTOR_HID:
// if (!valParser.Parse(pp, pcntdn))
@ -180,44 +191,47 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
theBuffer.pValue = varBuffer;
stateParseDescr = 0;
}
#pragma GCC diagnostic pop
return true;
}
template <const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
void ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) {
Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80);
Notify(PSTR("bDescLength:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bLength, 0x80);
Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80);
Notify(PSTR("bDescLength:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bLength, 0x80);
Notify(PSTR("\r\nbDescriptorType:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bDescriptorType, 0x80);
Notify(PSTR("\r\nbDescriptorType:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bDescriptorType, 0x80);
Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80);
PrintHex<uint16_t > (pDesc->bcdHID, 0x80);
Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80);
PrintHex<uint16_t > (pDesc->bcdHID, 0x80);
Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bCountryCode, 0x80);
Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bCountryCode, 0x80);
Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bNumDescriptors, 0x80);
Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bNumDescriptors, 0x80);
//Notify(PSTR("\r\nbDescrType:\t\t"));
//PrintHex<uint8_t>(pDesc->bDescrType);
//
//Notify(PSTR("\r\nwDescriptorLength:\t"));
//PrintHex<uint16_t>(pDesc->wDescriptorLength);
//Notify(PSTR("\r\nbDescrType:\t\t"));
//PrintHex<uint8_t>(pDesc->bDescrType);
//
//Notify(PSTR("\r\nwDescriptorLength:\t"));
//PrintHex<uint16_t>(pDesc->wDescriptorLength);
for (uint32_t i = 0; i < pDesc->bNumDescriptors; i++) {
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE *pLT = (HID_CLASS_DESCRIPTOR_LEN_AND_TYPE*)&(pDesc->bDescrType);
Notify(PSTR("\r\nbDescrType:\t\t"), 0x80);
PrintHex<uint8_t > (pLT[i].bDescrType, 0x80);
Notify(PSTR("\r\nbDescrType:\t\t"), 0x80);
PrintHex<uint8_t > (pLT[i].bDescrType, 0x80);
Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80);
PrintHex<uint16_t > (pLT[i].wDescriptorLength, 0x80);
}
Notify(PSTR("\r\n"), 0x80);
Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80);
PrintHex<uint16_t > (pLT[i].wDescriptorLength, 0x80);
}
Notify(PSTR("\r\n"), 0x80);
}
#endif // __CONFDESCPARSER_H__

View file

@ -994,7 +994,6 @@ void ReportDescParserBase::Parse(const uint32_t len, const uint8_t *pbuf, const
uint32_t cntdn = (uint32_t)len;
uint8_t *p = (uint8_t*)pbuf;
totalSize = 0;
while(cntdn) {
@ -1091,6 +1090,17 @@ void ReportDescParserBase::PrintItemTitle(uint8_t prefix) {
uint8_t ReportDescParserBase::ParseItem(uint8_t **pp, uint32_t *pcntdn) {
//uint8_t ret = enErrorSuccess;
//reinterpret_cast<>(varBuffer);
#pragma GCC diagnostic push // Available since GCC 4.6.4
/*
* FIXME -- Enabled and review all `-Wimplicit-fallthrough` messages
* This code has multiple switch statements that "fall through" to the
* next case -- but it's not always clear if this is intentional or not.
* Review and commenting of code, and reducing cyclomatic complexity
* are highly recommended....
*/
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
switch(itemParseState) {
case 0:
if(**pp == HID_LONG_ITEM_PREFIX)
@ -1207,6 +1217,7 @@ uint8_t ReportDescParserBase::ParseItem(uint8_t **pp, uint32_t *pcntdn) {
} // switch (**pp & (TYPE_MASK | TAG_MASK))
}
} // switch (itemParseState)
#pragma GCC diagnostic pop
itemParseState = 0;
return enErrorSuccess;
}
@ -1236,18 +1247,18 @@ void ReportDescParserBase::SetUsagePage(uint16_t page) {
if(VALUE_BETWEEN(page, 0x00, 0x11))
pfUsage = (usagePageFunctions[page - 1]);
// Dead code...
//
// pfUsage = (UsagePageFunc)pgm_read_pointer(usagePageFunctions[page - 1]);
//else if (page > 0x7f && page < 0x84)
// E_Notify(pstrUsagePageMonitor);
//else if (page > 0x83 && page < 0x8c)
// E_Notify(pstrUsagePagePower);
//else if (page > 0x8b && page < 0x92)
// E_Notify((char*)pgm_read_pointer(&usagePageTitles1[page - 0x8c]));
//else if (page > 0xfeff && page <= 0xffff)
// E_Notify(pstrUsagePageVendorDefined);
//
// Dead code...
//
// pfUsage = (UsagePageFunc)pgm_read_pointer(usagePageFunctions[page - 1]);
//else if (page > 0x7f && page < 0x84)
// E_Notify(pstrUsagePageMonitor);
//else if (page > 0x83 && page < 0x8c)
// E_Notify(pstrUsagePagePower);
//else if (page > 0x8b && page < 0x92)
// E_Notify((char*)pgm_read_pointer(&usagePageTitles1[page - 0x8c]));
//else if (page > 0xfeff && page <= 0xffff)
// E_Notify(pstrUsagePageVendorDefined);
//
else
switch(page) {
case 0x14:
@ -1440,6 +1451,15 @@ void ReportDescParserBase::PrintMedicalInstrumentPageUsage(uint16_t usage) {
uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint32_t *pcntdn) {
//uint8_t ret = enErrorSuccess;
#pragma GCC diagnostic push // Available since GCC 4.6.4
/*
* FIXME -- Enabled and review all `-Wimplicit-fallthrough` messages
* This code has multiple switch statements that "fall through" to the
* next case -- but it's not always clear if this is intentional or not.
* Review and commenting of code, and reducing cyclomatic complexity
* are highly recommended....
*/
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
switch(itemParseState) {
case 0:
if(**pp == HID_LONG_ITEM_PREFIX)
@ -1519,6 +1539,8 @@ uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint32_t *pcntdn) {
} // switch (**pp & (TYPE_MASK | TAG_MASK))
}
} // switch (itemParseState)
#pragma GCC diagnostic pop
itemParseState = 0;
return enErrorSuccess;
}
@ -1558,8 +1580,7 @@ void ReportDescParser2::OnInputItem(uint8_t itm) {
// bits_to_copy - number of bits to copy to result buffer
// for each bit in a field
for(uint8_t bits_left = rptSize, bits_to_copy = 0; bits_left;
bits_left -= bits_to_copy) {
for(uint8_t bits_left = rptSize, bits_to_copy = 0; bits_left; bits_left -= bits_to_copy) {
bits_to_copy = (bits_left > bits_of_byte) ? bits_of_byte : bits_left;
result.dwResult <<= bits_to_copy; // Result buffer is shifted by the number of bits to be copied into it

View file

@ -17,14 +17,14 @@ e-mail : support@circuitsathome.com
#include "Usb.h"
bool MultiByteValueParser::Parse(uint8_t **pp, uint32_t *pcntdn) {
if(!pBuf) {
Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
if(!pBuf) {
Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
return false;
}
for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
pBuf[valueSize - countDown] = (**pp);
if(countDown)
if(countDown)
return false;
countDown = valueSize;
@ -32,36 +32,48 @@ bool MultiByteValueParser::Parse(uint8_t **pp, uint32_t *pcntdn) {
}
bool PTPListParser::Parse(uint8_t **pp, uint32_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) {
switch(nStage) {
case 0:
pBuf->valueSize = lenSize;
theParser.Initialize(pBuf);
nStage = 1;
case 1:
if(!theParser.Parse(pp, pcntdn))
return false;
#pragma GCC diagnostic push // Available since GCC 4.6.4
/*
* FIXME -- Enabled and review all `-Wimplicit-fallthrough` messages
* This code has multiple switch statements that "fall through" to the
* next case -- but it's not always clear if this is intentional or not.
* Review and commenting of code, and reducing cyclomatic complexity
* are highly recommended....
*/
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
arLen = 0;
arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
arLenCntdn = arLen;
nStage = 2;
switch(nStage) {
case 0:
pBuf->valueSize = lenSize;
theParser.Initialize(pBuf);
nStage = 1;
case 2:
pBuf->valueSize = valSize;
theParser.Initialize(pBuf);
nStage = 3;
case 3:
for(; arLenCntdn; arLenCntdn--) {
case 1:
if(!theParser.Parse(pp, pcntdn))
return false;
arLen = 0;
arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
arLenCntdn = arLen;
nStage = 2;
case 2:
pBuf->valueSize = valSize;
theParser.Initialize(pBuf);
nStage = 3;
case 3:
for(; arLenCntdn; arLenCntdn--) {
if(!theParser.Parse(pp, pcntdn))
return false;
if(pf)
pf(pBuf, (arLen - arLenCntdn), me);
}
nStage = 0;
}
#pragma GCC diagnostic pop
return true;
}

View file

@ -35,12 +35,12 @@ class MultiByteValueParser {
public:
MultiByteValueParser() : pBuf(NULL), countDown(0), valueSize(0) {
};
MultiByteValueParser() : pBuf(NULL), countDown(0), valueSize(0) {
};
const uint8_t* GetBuffer() {
return pBuf;
};
const uint8_t* GetBuffer() {
return pBuf;
};
void Initialize(MultiValueBuffer * const pbuf) {
pBuf = (uint8_t*)pbuf->pValue;
@ -58,7 +58,7 @@ class ByteSkipper {
public:
ByteSkipper() : pBuf(NULL), nStage(0), countDown(0) {
};
};
void Initialize(MultiValueBuffer *pbuf) {
pBuf = (uint8_t*)pbuf->pValue;
@ -66,16 +66,25 @@ public:
};
bool Skip(uint8_t **pp, uint32_t *pcntdn, uint32_t bytes_to_skip) {
switch(nStage) {
case 0:
countDown = bytes_to_skip;
nStage++;
case 1:
for(; countDown && (*pcntdn); countDown--, (*pp)++, (*pcntdn)--);
if(!countDown)
nStage = 0;
#pragma GCC diagnostic push // Available since GCC 4.6.4
/*
* FIXME -- Enabled and review all `-Wimplicit-fallthrough` messages
* This code has multiple switch statements that "fall through" to the
* next case -- but it's not always clear if this is intentional or not.
* Review and commenting of code, and reducing cyclomatic complexity
* are highly recommended....
*/
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
switch(nStage) {
case 0:
countDown = bytes_to_skip;
nStage++;
case 1:
for(; countDown && (*pcntdn); countDown--, (*pp)++, (*pcntdn)--);
if(!countDown)
nStage = 0;
};
#pragma GCC diagnostic pop
return (!countDown);
};
};
@ -86,9 +95,9 @@ typedef void (*PTP_ARRAY_EL_FUNC)(const MultiValueBuffer * const p, uint32_t cou
class PTPListParser {
public:
enum ParseMode {
modeArray, modeRange/*, modeEnum*/
};
enum ParseMode {
modeArray, modeRange/*, modeEnum*/
};
private:
uint32_t nStage;

View file

@ -28,6 +28,8 @@ void loop()
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
(void)howMany; // avoid compiler warning about unused parameter
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character

View file

@ -51,7 +51,10 @@
#define portInputRegister(port) (&(port->IN.reg))
#define portModeRegister(port) (&(port->DIR.reg))
#define digitalPinHasPWM(P) (g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER)
#define digitalPinToInterrupt(P) (g_APinDescription[P].ulExtInt)
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE < 10606)
#define digitalPinToInterrupt(P) (g_APinDescription[P].ulExtInt)
#endif
/*
* digitalPinToTimer(..) is AVR-specific and is not defined for SAMD