sorta working, control needs to be improved

This commit is contained in:
2020-10-01 14:04:35 -07:00
parent f86e4d7c52
commit 90b9831079
62 changed files with 3221 additions and 510 deletions

View File

@@ -46,7 +46,7 @@ yun.build.extra_flags={build.usb_flags}
##############################################################
uno.name=Arduino/Genuino Uno
uno.name=Arduino Uno
uno.vid.0=0x2341
uno.pid.0=0x0043
@@ -185,7 +185,7 @@ nano.menu.cpu.atmega168.build.mcu=atmega168
##############################################################
mega.name=Arduino/Genuino Mega or Mega 2560
mega.name=Arduino Mega or Mega 2560
mega.vid.0=0x2341
mega.pid.0=0x0010
@@ -214,7 +214,7 @@ mega.build.variant=mega
# default board may be overridden by the cpu menu
mega.build.board=AVR_MEGA2560
## Arduino/Genuino Mega w/ ATmega2560
## Arduino Mega w/ ATmega2560
## -------------------------
mega.menu.cpu.atmega2560=ATmega2560 (Mega 2560)
@@ -353,7 +353,7 @@ leonardoeth.build.extra_flags={build.usb_flags}
##############################################################
micro.name=Arduino/Genuino Micro
micro.name=Arduino Micro
micro.vid.0=0x2341
micro.pid.0=0x0037
@@ -363,24 +363,10 @@ micro.vid.2=0x2A03
micro.pid.2=0x0037
micro.vid.3=0x2A03
micro.pid.3=0x8037
micro.vid.4=0x2341
micro.pid.4=0x0237
# If the board is a 2341:0237 use 2341:8237 for build and set
# other parameters as well
micro.vid.4.build.vid=0x2341
micro.vid.4.build.pid=0x8237
micro.vid.4.build.usb_product="Genuino Micro"
micro.vid.4.bootloader.file=caterina/Caterina-Genuino-Micro.hex
micro.vid.5=0x2341
micro.pid.5=0x8237
# If the board is a 2341:8237 use 2341:8237 for build and set
# other paramters as well
micro.vid.5.build.vid=0x2341
micro.vid.5.build.pid=0x8237
micro.vid.5.build.usb_product="Genuino Micro"
micro.vid.5.bootloader.file=caterina/Caterina-Genuino-Micro.hex
micro.upload.tool=avrdude
micro.upload.protocol=avr109
@@ -946,7 +932,7 @@ yunmini.bootloader.tool=avrdude
yunmini.bootloader.low_fuses=0xff
yunmini.bootloader.high_fuses=0xd8
yunmini.bootloader.extended_fuses=0xfb
yunmini.bootloader.file=caterina/Caterina-Yunmini.hex
yunmini.bootloader.file=caterina/Caterina-YunMini.hex
yunmini.bootloader.unlock_bits=0x3F
yunmini.bootloader.lock_bits=0x2F

View File

@@ -1,257 +0,0 @@
:1070000055C000006EC000006CC000006AC00000E7
:1070100068C0000066C0000064C0000062C00000DC
:1070200060C000005EC00000F2C400005AC0000052
:1070300058C0000056C0000054C0000052C00000FC
:1070400050C0000078C000004CC000004AC00000E2
:1070500048C0000046C0000044C0000042C000001C
:1070600040C000003EC000003CC000003AC000002C
:1070700038C0000036C0000034C0000032C000003C
:1070800030C000002EC000002CC000002AC000004C
:1070900028C0000026C0000024C0000022C000005C
:1070A00020C000001EC000001CC0000011241FBE34
:1070B000CFEFDAE0DEBFCDBF11E0A0E0B1E0E2E368
:1070C000FFE702C005900D92A83AB107D9F711E089
:1070D000A8EAB1E001C01D92AE3BB107E1F78FD342
:1070E00026C78ECFF89410926F00109281001092F4
:1070F00085001092840081E085BF15BE47985D9899
:1071000028980C94000008952091B2013091B301A9
:107110002F5F3F4F3093B3012093B201932F37FF7E
:1071200003C08EEF831B982F990F921710F4479886
:107130000895479A08951F920F920FB60F92112447
:107140002F938F939F93EF93FF931092850010924C
:1071500084008091A8019091A901009741F00197C6
:107160009093A9018093A801892B09F45D988091DF
:10717000AA019091AB01009741F001979093AB0168
:107180008093AA01892B09F42898E0E0F0E085912A
:1071900094918F5F9F4F49F08091AC019091AD0128
:1071A00001969093AD018093AC01FF91EF919F9177
:1071B0008F912F910F900FBE0F901F90189584E024
:1071C0008093E9000DC08091E8008B778093E80000
:1071D00003C08EB3882351F08091E80082FFF9CF7D
:1071E0008091E80085FFEFCF8091F1000895982FFE
:1071F00083E08093E9008091E80085FD0DC08091D7
:10720000E8008E778093E80003C08EB3882369F08E
:107210008091E80080FFF9CF9093F1005D9A84E6B9
:1072200090E09093A9018093A80108954F925F92F6
:107230006F927F928F929F92AF92BF92CF92DF9286
:10724000EF92FF920F931F93CF93DF9384E080938D
:10725000E9008091E80082FF57C2289A84E690E016
:107260009093AB018093AA01AADF182F853481F493
:107270008CE49DE19093AD018093AC0107B600FCD6
:10728000FDCFF999FECF81E180935700E89503C0C7
:10729000843519F494DF8DE00DC28C34E1F3803530
:1072A000D1F3843721F484E4A2DF80E003C2813685
:1072B00011F489E5FFC18134B1F481DF182F7FDF3C
:1072C00090E0880F991FAA2797FDA095BA2F312F1C
:1072D000330F20E0442737FD4095542F822B932B0A
:1072E000A42BB52BB8C1803711F483E5E3C18335F6
:1072F00049F4C0E0D1E089917ADF21E0C730D207BC
:10730000D1F7D9C1863521F481E371DF80E3D2C1A1
:10731000833731F487E86BDF85E969DF8EE1CAC125
:107320008536B9F4E0E0F0E093E085E09093570013
:10733000E89507B600FCFDCF80935700E89507B6A7
:1073400000FCFDCFE058FF4FA0E7E030FA0771F7EF
:10735000A2CF823739F4E1E0F0E089E08093570072
:107360008491A8C1863439F4E0E0F0E089E08093AC
:10737000570084919FC18E3439F4E3E0F0E089E056
:1073800080935700849196C1813539F4E2E0F0E0B2
:1073900089E08093570084918DC1823631F489E56C
:1073A00026DF80E024DF80E885C1823419F087364B
:1073B00009F0E5C01092AD011092AC0100DF082F7A
:1073C000FEDEF82EFCDE682E8554823008F071C196
:1073D000902F80E0CF2DD0E0C82BD92B10926F00DA
:1073E000173609F04BC081E180935700E895DD2402
:1073F000CC24C3943FC0E090AE01F090AF01009167
:10740000B0011091B101B6E46B16D9F4ED2DF0E0A6
:10741000EE29FF29E4918E2FEADEDD2081F082E063
:1074200090E0A0E0B0E0E80EF91E0A1F1B1FE092FA
:10743000AE01F092AF010093B0011093B101DC24D2
:1074400018C0D801C701B695A7959795879559D5C6
:10745000CEDE82E090E0A0E0B0E0E80EF91E0A1F68
:107460001B1FE092AE01F092AF010093B0011093A8
:10747000B1012197209709F0BECF7DC08090AE0169
:107480009090AF01A090B001B090B10196E4691660
:1074900009F05DC083E0F40180935700E89507B6DA
:1074A00000FCFDCF54C0F6E46F1661F5772031F192
:1074B000E090AE01F090AF010091B0011091B101E8
:1074C0007EDED82ECC24852D90E08C299D29F701D5
:1074D0000C0140925700E895112482E090E0A0E072
:1074E000B0E0E80EF91E0A1F1B1FE092AE01F092F9
:1074F000AF010093B0011093B10102C060DE582EBD
:10750000742423C0E090AE01F090AF010091B0016F
:107510001091B10116950795F794E79450DE682F06
:10752000C701F7D48091AE019091AF01A091B00155
:10753000B091B1010296A11DB11D8093AE0190934F
:10754000AF01A093B001B093B101219704C05524BD
:10755000772444244394209709F0A5CF96E4691634
:1075600041F485E0F40180935700E89507B600FCEC
:10757000FDCF8DE03CDE82E080936F009CC08334C1
:1075800071F40091AE011091AF0119DE90E021E09D
:10759000F8010C0120935700E89511247CCE833626
:1075A00019F5E090AE01F090AF010091B00110919B
:1075B000B10105DEF701E16090E021E00C012093CC
:1075C0005700E895112482E090E0A0E0B0E0E80EDA
:1075D000F91E0A1F1B1FE092AE01F092AF0100934B
:1075E000B0011093B10157CE8D3661F4E091AE0138
:1075F000F091AF0185E080935700E89507B600FC55
:10760000FDCF49CE823551F4E091AE01F091AF014A
:1076100005911491812FEBDD802F4CC0843421F52E
:10762000E090AE01F090AF010091B0011091B10176
:1076300016950795F794E794C2DD682FC70169D4C2
:107640008091AE019091AF01A091B001B091B101D4
:107650000296A11DB11D8093AE019093AF01A0933E
:10766000B001B093B10117CE843609F5E090AE01B8
:10767000F090AF010091B0011091B101D801C701A4
:10768000B695A795979587953CD4B1DD82E090E0BB
:10769000A0E0B0E0E80EF91E0A1F1B1FE092AE0149
:1076A000F092AF010093B0011093B10104C08B318F
:1076B00011F08FE39CDD83E08093E9009091E80076
:1076C0008091E8008E778093E80095FF04C010C099
:1076D0008EB38823C9F08091E80080FFF9CF8091B4
:1076E000E8008E778093E80003C08EB3882361F0B2
:1076F0008091E80080FFF9CF84E08093E9008091D9
:10770000E8008B778093E800DF91CF911F910F9174
:10771000FF90EF90DF90CF90BF90AF909F908F90B1
:107720007F906F905F904F9008959091B601892F50
:107730008F77813249F58091B7018032A1F0813293
:1077400019F5913A09F58091E800877F8093E80068
:107750008DE091E067E070E00BD28091E8008B77DC
:107760008093E8000895913279F48091E800877F52
:107770008093E8008DE091E067E070E05DD2809159
:10778000E8008E778093E800089582E061EC42E0A3
:10779000B5D083E061E842E1B1D084E060E842E145
:1077A000ADC084B7877F84BF88E10FB6F89480931B
:1077B0006000109260000FBE20E880E090E00FB6FD
:1077C000F89420936100809361000FBE81E085BF33
:1077D00092E095BF3F9A209A559AE1E6F0E0208327
:1077E000108247985D982898109289008AEF8093BC
:1077F000880090936F0083E080938100F0C04091F7
:10780000000850910108109201081092000894B7E6
:1078100014BE88E10FB6F894809360001092600067
:107820000FBE292F30E0F901E270F07091FD18C011
:1078300090FF05C0859194918F5F9F4F81F423FF46
:107840000FC08091090190910A014817590741F032
:10785000E0E0F0E0859194918F5F9F4F09F042DC6A
:10786000A0DF78941092AD011092AC010CC0DEDC68
:1078700036D38091AC019091AD0181549F4110F0BD
:107880001092140141DC80911401882381F78091CA
:10789000E00081608093E00025DC80E090E00895C6
:1078A000FA01923049F0933061F09130F9F485E1BA
:1078B00091E022E130E01EC087E291E02EE330E06B
:1078C00019C0882329F485E691E024E030E012C055
:1078D000813029F489E691E022E230E00BC0823069
:1078E00029F48DE891E028E130E004C080E090E0E8
:1078F00020E030E091838083C90108958093E900FE
:107900008091EB0081608093EB001092ED0060931A
:10791000EC004093ED008091EE00881F8827881FBF
:1079200008958091B60188238CF403C08EB3882318
:10793000B1F08091E80082FFF9CF8091E8008B7769
:107940008093E80008958EB3882349F08091E80081
:1079500080FFF9CF8091E8008E778093E80008954A
:10796000EF92FF920F931F9345D04CD008ED10E09B
:10797000F80180818F778083808180688083808117
:107980008F7D808319BC1EBA1092B40180EEE82E60
:10799000F12CF70180818B7F8083F80180818160E9
:1079A000808380E060E042E0A9DFE1EEF0E08081EA
:1079B0008E7F8083E2EEF0E0808181608083808131
:1079C00088608083F70180818E7F8083F8018081C9
:1079D000806180831F910F91FF90EF900895E7EDF4
:1079E000F0E08081816080838AE482BF81E08093BF
:1079F000B501B6CFE8EDF0E080818E7F80831092F4
:107A0000E20008951092DA001092E10008951F92AA
:107A10000F920FB60F9211242F933F934F935F93C2
:107A20006F937F938F939F93AF93BF93EF93FF9346
:107A30008091DA0080FF1BC08091D80080FF17C0C2
:107A40008091DA008E7F8093DA008091D90080FFE8
:107A50000BC080E189BD82E189BD09B400FEFDCF84
:107A600081E08EBB3BD203C019BC1EBA37D28091D5
:107A7000E10080FF17C08091E20080FF13C0809179
:107A8000E2008E7F8093E2008091E200806180932B
:107A9000E2008091D80080628093D80019BC85E014
:107AA0008EBB1CD28091E10084FF2CC08091E2004B
:107AB00084FF28C080E189BD82E189BD09B400FE50
:107AC000FDCF8091D8008F7D8093D8008091E10018
:107AD0008F7E8093E1008091E2008F7E8093E200B0
:107AE0008091E20081608093E2008091B40188235C
:107AF00031F48091E30087FD02C081E001C084E0A1
:107B00008EBBECD18091E10083FF21C08091E20027
:107B100083FF1DC08091E100877F8093E10082E0B8
:107B20008EBB1092B4018091E1008E7F8093E100C2
:107B30008091E2008E7F8093E2008091E20080617C
:107B40008093E20080E060E042E0D8DEC7D1FF91A0
:107B5000EF91BF91AF919F918F917F916F915F91C5
:107B60004F913F912F910F900FBE0F901F9018953E
:107B70009C014091BC015091BD014617570718F474
:107B8000F90190E044C06115710511F0AB01F8CF27
:107B90008091E8008E778093E80040E050E0F0CFDD
:107BA0008EB3882309F444C0853009F443C0809122
:107BB000E80083FF02C081E008958091E80082FD23
:107BC00031C08091E80080FF22C08091F300909145
:107BD000F200782F60E0292F30E0262B372B07C0EA
:107BE00081918093F100415050402F5F3F4F4115EC
:107BF000510519F02830310598F390E0283031050F
:107C000009F491E08091E8008E778093E8004115B7
:107C1000510531F6992321F605C08EB3882341F032
:107C2000853041F08091E80082FFF7CF80E0089531
:107C300082E0089583E008959C016115710529F49F
:107C40008091E8008B778093E800F90126C08EB31D
:107C5000882391F1853091F18091E80083FF02C083
:107C600081E008958091E80082FFF1CF06C0809105
:107C7000F10081936150704059F02091F3008091A0
:107C8000F200322F20E090E0822B932B892B79F7A2
:107C90008091E8008B778093E80061157105B9F653
:107CA00005C08EB3882341F0853041F08091E80013
:107CB00080FFF7CF80E0089582E0089583E0089583
:107CC0000F931F93DF93CF9300D0CDB7DEB7E6EBD2
:107CD000F1E08091F100819381E0EE3BF807C9F774
:107CE00024DD8091E80083FFE4C08091B60190918B
:107CF000B701953009F46DC0963040F4913081F1B0
:107D0000913070F0933009F0D4C02AC0983009F453
:107D1000A3C0993009F4B2C0963009F0CAC07CC043
:107D2000803809F4C6C0823809F0C3C08091BA0116
:107D300087708093E9008091EB001092E900209118
:107D4000E800277F2093E80090E025E0969587954E
:107D50002A95E1F781708093F1001092F10087C0BD
:107D6000882319F0823009F0A4C08F71823009F0A5
:107D7000A0C08091B801882331F52091BA01277005
:107D800009F497C02093E9008091EB0080FF1BC0AD
:107D9000933021F48091EB00806213C08091EB005E
:107DA00080618093EB0081E090E002C0880F991F12
:107DB0002A95E2F78093EA001092EA008091EB00A6
:107DC00088608093EB001092E9008091E800877F43
:107DD00051C0882309F06DC01091B8011F770FB70B
:107DE000F8948091E800877F8093E8009ADD809185
:107DF000E80080FFFCCF8091E3008078812B8093A6
:107E0000E30080688093E300112311F482E001C055
:107E100083E08EBB0FBF4DC08058823008F049C050
:107E20008091B8019091B9016091BA01AE014F5FA4
:107E30005F4F36DDBC01009709F43BC08091E8003C
:107E4000877F8093E80089819A8192DE8091E800A3
:107E50008B778093E8002DC0803859F58091E80039
:107E6000877F8093E8008091B4018093F100809136
:107E7000E8008E778093E80054DD1BC08823C9F4A6
:107E80009091B8019230A8F48091E800877F8093A8
:107E9000E8009093B40145DD8091B401882331F46A
:107EA0008091E30087FD02C081E001C084E08EBBC9
:107EB0006CDC8091E80083FF0AC08091EB00806257
:107EC0008093EB008091E800877F8093E8000F901B
:107ED0000F90CF91DF911F910F91089508951F93F7
:107EE0008EB3882361F01091E9001092E90080912F
:107EF000E80083FF01C0E4DE17701093E9001F91D2
:107F00000895F999FECF92BD81BDF89A992780B561
:107F10000895262FF999FECF1FBA92BD81BD20BDCD
:107F20000FB6F894FA9AF99A0FBE01960895F8944C
:027F3000FFCF81
:107F32004341544552494E41007777000800000002
:107F4200000000080112011001020000084123375D
:107F52000201000201000109023E0002010080321A
:107F6200090400000102020100052400100104249A
:107F720002040524060001070582030800FF090424
:107F82000100020A000000070504021000010705B3
:107F92008302100001040309042203470065006EF6
:107FA20000750069006E006F0020004D00690063DB
:107FB2000072006F00200020002000000018034122
:107FC2000072006400750069006E006F0020004CB2
:087FD200004C00430000000018
:040000030000700089
:00000001FF

View File

@@ -1,19 +0,0 @@
GENUINO MICRO PRODUCTION FIRMWARES
==================================
Bootloader:
-----------
Name: Caterina-Genuino-Micro.hex
Notes:
Builds against LUFA version 111009
make version 3.81
avrdude version 5.11
All AVR tools except avrdude were installed by CrossPack 20100115:
avr-gcc version 4.3.3 (GCC)
Thread model: single
Configured with: ../configure —prefix=/usr/local/CrossPack-AVR-20100115 —disable-dependency-tracking —disable-nls —disable-werror —target=avr —enable-languages=c,c++ —disable-nls —disable-libssp —with-dwarf2
avr-libc version 1.6.7
binutils version 2.19

View File

@@ -111,7 +111,8 @@ void yield(void);
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
// avr-libc defines _NOP() since 1.6.2
#ifndef _NOP
@@ -130,16 +131,16 @@ void initVariant(void);
int atexit(void (*func)()) __attribute__((weak));
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void pinMode(uint8_t pin, uint8_t mode);
void digitalWrite(uint8_t pin, uint8_t val);
int digitalRead(uint8_t pin);
int analogRead(uint8_t pin);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
void analogWrite(uint8_t pin, int val);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
void delay(unsigned long ms);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
@@ -147,8 +148,8 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);
void detachInterrupt(uint8_t interruptNum);
void setup(void);
void loop(void);

View File

@@ -41,7 +41,7 @@ static u8 wdtcsr_save;
extern const CDCDescriptor _cdcInterface PROGMEM;
const CDCDescriptor _cdcInterface =
{
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
// CDC communication interface
D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),

View File

@@ -26,7 +26,7 @@
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// Each HardwareSerial is defined in its own file, since the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the

View File

@@ -26,7 +26,7 @@
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// Each HardwareSerial is defined in its own file, since the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the

View File

@@ -26,7 +26,7 @@
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// Each HardwareSerial is defined in its own file, since the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the

View File

@@ -26,7 +26,7 @@
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// Each HardwareSerial is defined in its own file, since the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the

View File

@@ -218,7 +218,6 @@ size_t Stream::readBytes(char *buffer, size_t length)
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
if (length < 1) return 0;
size_t index = 0;
while (index < length) {
int c = timedRead();

View File

@@ -180,12 +180,12 @@ static int8_t toneBegin(uint8_t _pin)
#if defined(TCCR2A) && defined(TCCR2B)
case 2:
// 8 bit timer
// TCCR2A = 0;
// TCCR2B = 0;
// bitWrite(TCCR2A, WGM21, 1);
// bitWrite(TCCR2B, CS20, 1);
// timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
// timer2_pin_mask = digitalPinToBitMask(_pin);
TCCR2A = 0;
TCCR2B = 0;
bitWrite(TCCR2A, WGM21, 1);
bitWrite(TCCR2B, CS20, 1);
timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer2_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
@@ -304,7 +304,7 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
#endif
#if defined(TCCR2B)
{
// TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
}
#else
{
@@ -385,9 +385,9 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
#if defined(OCR2A) && defined(TIMSK2) && defined(OCIE2A)
case 2:
// OCR2A = ocr;
// timer2_toggle_count = toggle_count;
// bitWrite(TIMSK2, OCIE2A, 1);
OCR2A = ocr;
timer2_toggle_count = toggle_count;
bitWrite(TIMSK2, OCIE2A, 1);
break;
#endif
@@ -443,16 +443,16 @@ void disableTimer(uint8_t _timer)
case 2:
#if defined(TIMSK2) && defined(OCIE2A)
// bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
#endif
#if defined(TCCR2A) && defined(WGM20)
// TCCR2A = (1 << WGM20);
TCCR2A = (1 << WGM20);
#endif
#if defined(TCCR2B) && defined(CS22)
// TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
#endif
#if defined(OCR2A)
// OCR2A = 0;
OCR2A = 0;
#endif
break;
@@ -534,7 +534,7 @@ ISR(TIMER1_COMPA_vect)
#endif
#ifdef NOPE //USE_TIMER2
#ifdef USE_TIMER2
ISR(TIMER2_COMPA_vect)
{

View File

@@ -65,6 +65,8 @@ public:
void detach(); // Serial port goes down too...
void poll();
bool wakeupHost(); // returns false, when wakeup cannot be processed
bool isSuspended();
};
extern USBDevice_ USBDevice;

View File

@@ -496,14 +496,13 @@ bool SendConfiguration(int maxlen)
static
bool SendDescriptor(USBSetup& setup)
{
int ret;
u8 t = setup.wValueH;
if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
return SendConfiguration(setup.wLength);
InitControl(setup.wLength);
#ifdef PLUGGABLE_USB_ENABLED
ret = PluggableUSB().getDescriptor(setup);
int ret = PluggableUSB().getDescriptor(setup);
if (ret != 0) {
return (ret > 0 ? true : false);
}
@@ -855,4 +854,10 @@ bool USBDevice_::wakeupHost()
return false;
}
bool USBDevice_::isSuspended()
{
return (_usbSuspendState & (1 << SUSPI));
}
#endif /* if defined(USBCON) */

View File

@@ -97,6 +97,9 @@
// bMaxPower in Configuration Descriptor
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
#ifndef USB_CONFIG_POWER
#define USB_CONFIG_POWER (500)
#endif
// bEndpointAddress in Endpoint Descriptor
#define USB_ENDPOINT_DIRECTION_MASK 0x80
@@ -267,7 +270,7 @@ typedef struct
{ 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
#define D_CONFIG(_totalLength,_interfaces) \
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) }
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(USB_CONFIG_POWER) }
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }

View File

@@ -65,7 +65,6 @@ static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] = {
nothing,
#endif
};
// volatile static voidFuncPtr twiIntFunc;
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
@@ -103,6 +102,39 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
EICRB = (EICRB & ~((1<<ISC60) | (1<<ISC61))) | (mode << ISC60);
EIMSK |= (1<<INT6);
break;
#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)
case 0:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
break;
case 1:
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
break;
case 2:
EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
EIMSK |= (1 << INT2);
break;
case 3:
EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
EIMSK |= (1 << INT3);
break;
case 4:
EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
EIMSK |= (1 << INT4);
break;
case 5:
EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
EIMSK |= (1 << INT5);
break;
case 6:
EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
EIMSK |= (1 << INT6);
break;
case 7:
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
EIMSK |= (1 << INT7);
break;
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
@@ -205,7 +237,32 @@ void detachInterrupt(uint8_t interruptNum) {
break;
case 4:
EIMSK &= ~(1<<INT6);
break;
break;
#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)
case 0:
EIMSK &= ~(1 << INT0);
break;
case 1:
EIMSK &= ~(1 << INT1);
break;
case 2:
EIMSK &= ~(1 << INT2);
break;
case 3:
EIMSK &= ~(1 << INT3);
break;
case 4:
EIMSK &= ~(1 << INT4);
break;
case 5:
EIMSK &= ~(1 << INT5);
break;
case 6:
EIMSK &= ~(1 << INT6);
break;
case 7:
EIMSK &= ~(1 << INT7);
break;
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EIMSK &= ~(1 << INT0);
@@ -274,11 +331,6 @@ void detachInterrupt(uint8_t interruptNum) {
}
}
/*
void attachInterruptTwi(void (*userFunc)(void) ) {
twiIntFunc = userFunc;
}
*/
#define IMPLEMENT_ISR(vect, interrupt) \
ISR(vect) { \
@@ -293,6 +345,17 @@ IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2)
IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_3)
IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_4)
#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)
IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_0)
IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1)
IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2)
IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_3)
IMPLEMENT_ISR(INT4_vect, EXTERNAL_INT_4)
IMPLEMENT_ISR(INT5_vect, EXTERNAL_INT_5)
IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_6)
IMPLEMENT_ISR(INT7_vect, EXTERNAL_INT_7)
#elif defined(EICRA) && defined(EICRB)
IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_2)
@@ -314,11 +377,3 @@ IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2)
#endif
#endif
/*
ISR(TWI_vect) {
if(twiIntFunc)
twiIntFunc();
}
*/

View File

@@ -121,7 +121,7 @@ String::String(double value, unsigned char decimalPlaces)
String::~String()
{
free(buffer);
if (buffer) free(buffer);
}
/*********************************************/

View File

@@ -39,14 +39,14 @@ void setupUSB() { }
//#if defined(USBCON)
// USBDevice.attach();
//#endif
//
//
// setup();
//
//
// for (;;) {
// loop();
// if (serialEventRun) serialEventRun();
// }
//
//
// return 0;
//}

View File

@@ -0,0 +1,5 @@
/*
this header is for compatibility with standard c++ header names
so that #include<new> works as expected
*/
#include "new.h"

View File

@@ -26,6 +26,11 @@ void *operator new[](size_t size) {
return malloc(size);
}
void * operator new(size_t size, void * ptr) noexcept {
(void)size;
return ptr;
}
void operator delete(void * ptr) {
free(ptr);
}

View File

@@ -23,6 +23,7 @@
void * operator new(size_t size);
void * operator new[](size_t size);
void * operator new(size_t size, void * ptr) noexcept;
void operator delete(void * ptr);
void operator delete[](void * ptr);

View File

@@ -164,7 +164,7 @@ void analogWrite(uint8_t pin, int val)
#if defined(TCCR1A) && defined(COM1C1)
case TIMER1C:
// connect pwm to pin on timer 1, channel B
// connect pwm to pin on timer 1, channel C
sbi(TCCR1A, COM1C1);
OCR1C = val; // set pwm duty
break;

View File

@@ -91,27 +91,3 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
}
return micros() - start;
}
#include <Arduino.h>
#include <stdlib.h>
unsigned long countPulseASM(volatile uint8_t *port, uint8_t bit, uint8_t stateMask, unsigned long maxloops)
{
unsigned long width = 0;
// wait for any previous pulse to end
while ((*port & bit) == stateMask)
if (--maxloops == 0)
return 0;
// wait for the pulse to start
while ((*port & bit) != stateMask)
if (--maxloops == 0)
return 0;
// wait for the pulse to stop
while ((*port & bit) == stateMask) {
if (++width == maxloops)
return 0;
}
return width;
}

View File

@@ -42,10 +42,13 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
uint8_t i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
if (bitOrder == LSBFIRST) {
digitalWrite(dataPin, val & 1);
val >>= 1;
} else {
digitalWrite(dataPin, (val & 128) != 0);
val <<= 1;
}
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);

View File

@@ -0,0 +1,51 @@
#!/bin/bash -ex
# pack.*.bash - Bash script to help packaging avr core releases.
# Copyright (c) 2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
BUILD_NUMBER=$1
CURR_TIME=`date "+%Y-%m-%d %H:%M"`
CURR_TIME_SED=`date "+%Y\\-%m\\-%d %H:%M"`
VERSION=9.9.9-Hourly
PWD=`pwd`
FOLDERNAME=`basename $PWD`
THIS_SCRIPT_NAME=`basename $0`
FILENAME=package_avr-hourly-b${BUILD_NUMBER}.tar.bz2
rm -f $FILENAME
# Change name in platform.txt
sed -i "s/name=.*/name=SAMD Hourly Build ${BUILD_NUMBER} (${CURR_TIME})/" platform.txt
cd ..
tar --transform "s|$FOLDERNAME|avr-hourly_b${BUILD_NUMBER}|g" --exclude=extras/** --exclude=.git* --exclude=.idea -cjf $FILENAME $FOLDERNAME
cd -
mv ../$FILENAME .
CHKSUM=`sha256sum $FILENAME | awk '{ print $1 }'`
SIZE=`wc -c $FILENAME | awk '{ print $1 }'`
cat extras/package_index.json.Hourly.template |
sed "s/%%BUILD_NUMBER%%/${BUILD_NUMBER}/" |
sed "s/%%CURR_TIME%%/${CURR_TIME_SED}/" |
sed "s/%%VERSION%%/${VERSION}/" |
sed "s/%%FILENAME%%/${FILENAME}/" |
sed "s/%%CHECKSUM%%/${CHKSUM}/" |
sed "s/%%SIZE%%/${SIZE}/" > package_avr-hourly-build_index.json

View File

@@ -0,0 +1,50 @@
#!/bin/bash -ex
# pack.*.bash - Bash script to help packaging avr core releases.
# Copyright (c) 2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
PR_NUMBER=$1
BUILD_NUMBER=$2
VERSION=`grep version= platform.txt | sed 's/version=//g'`
PWD=`pwd`
FOLDERNAME=`basename $PWD`
THIS_SCRIPT_NAME=`basename $0`
FILENAME=package_avr-b${BUILD_NUMBER}.tar.bz2
rm -f $FILENAME
# Change name in platform.txt
sed -i "s/name=.*/name=SAMD Pull request #${PR_NUMBER} (Build ${BUILD_NUMBER})/" platform.txt
cd ..
tar --transform "s|$FOLDERNAME|avr-PR${PR_NUMBER}_b${BUILD_NUMBER}|g" --exclude=extras/** --exclude=.git* --exclude=.idea -cjf $FILENAME $FOLDERNAME
cd -
mv ../$FILENAME .
CHKSUM=`sha256sum $FILENAME | awk '{ print $1 }'`
SIZE=`wc -c $FILENAME | awk '{ print $1 }'`
cat extras/package_index.json.PR.template |
sed s/%%PR_NUMBER%%/${PR_NUMBER}/ |
sed s/%%BUILD_NUMBER%%/${BUILD_NUMBER}/ |
sed s/%%VERSION%%/${VERSION}-build-${BUILD_NUMBER}/ |
sed s/%%FILENAME%%/${FILENAME}/ |
sed s/%%CHECKSUM%%/${CHKSUM}/ |
sed s/%%SIZE%%/${SIZE}/ > package_avr-b${BUILD_NUMBER}_index.json

View File

@@ -0,0 +1,33 @@
#!/bin/bash -ex
# pack.*.bash - Bash script to help packaging avr core releases.
# Copyright (c) 2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
VERSION=`grep version= platform.txt | sed 's/version=//g'`
PWD=`pwd`
FOLDERNAME=`basename $PWD`
THIS_SCRIPT_NAME=`basename $0`
rm -f avr-$VERSION.tar.bz2
cd ..
tar --transform "s|$FOLDERNAME|$FOLDERNAME-$VERSION|g" --exclude=extras/** --exclude=.git* --exclude=.idea -cjf avr-$VERSION.tar.bz2 $FOLDERNAME
cd -
mv ../avr-$VERSION.tar.bz2 .

View File

@@ -0,0 +1,72 @@
{
"packages": [
{
"name": "arduino-beta",
"maintainer": "Arduino Betatesting",
"websiteURL": "http://www.arduino.cc/",
"email": "packages@arduino.cc",
"help": {
"online": "http://www.arduino.cc/en/Reference/HomePage"
},
"platforms": [
{
"name": "Arduino AVR core - Hourly build",
"architecture": "avr",
"version": "%%VERSION%%",
"category": "Arduino",
"url": "http://downloads.arduino.cc/Hourly/avr/%%FILENAME%%",
"archiveFileName": "%%FILENAME%%",
"checksum": "SHA-256:%%CHECKSUM%%",
"size": "%%SIZE%%",
"boards": [
{"name": "Arduino Yún"},
{"name": "Arduino Uno"},
{"name": "Arduino Uno WiFi"},
{"name": "Arduino Diecimila"},
{"name": "Arduino Nano"},
{"name": "Arduino Mega"},
{"name": "Arduino MegaADK"},
{"name": "Arduino Leonardo"},
{"name": "Arduino Leonardo Ethernet"},
{"name": "Arduino Micro"},
{"name": "Arduino Esplora"},
{"name": "Arduino Mini"},
{"name": "Arduino Ethernet"},
{"name": "Arduino Fio"},
{"name": "Arduino BT"},
{"name": "Arduino LilyPadUSB"},
{"name": "Arduino Lilypad"},
{"name": "Arduino Pro"},
{"name": "Arduino ATMegaNG"},
{"name": "Arduino Robot Control"},
{"name": "Arduino Robot Motor"},
{"name": "Arduino Gemma"},
{"name": "Adafruit Circuit Playground"},
{"name": "Arduino Yún Mini"},
{"name": "Arduino Industrial 101"},
{"name": "Linino One"}
],
"toolsDependencies": [
{
"packager": "arduino",
"name": "avr-gcc",
"version": "4.9.2-atmel3.5.4-arduino2"
},
{
"packager": "arduino",
"name": "avrdude",
"version": "6.3.0-arduino9"
},
{
"packager": "arduino",
"name": "arduinoOTA",
"version": "1.1.1"
}
]
}
],
"tools": [
]
}
]
}

View File

@@ -0,0 +1,72 @@
{
"packages": [
{
"name": "arduino-beta",
"maintainer": "Arduino Betatesting",
"websiteURL": "http://www.arduino.cc/",
"email": "packages@arduino.cc",
"help": {
"online": "http://www.arduino.cc/en/Reference/HomePage"
},
"platforms": [
{
"name": "Arduino AVR core - Pull request #%%PR_NUMBER%% (build %%BUILD_NUMBER%%)",
"architecture": "avr",
"version": "%%VERSION%%",
"category": "Arduino",
"url": "http://downloads.arduino.cc/PR/a/%%FILENAME%%",
"archiveFileName": "%%FILENAME%%",
"checksum": "SHA-256:%%CHECKSUM%%",
"size": "%%SIZE%%",
"boards": [
{"name": "Arduino Yún"},
{"name": "Arduino Uno"},
{"name": "Arduino Uno WiFi"},
{"name": "Arduino Diecimila"},
{"name": "Arduino Nano"},
{"name": "Arduino Mega"},
{"name": "Arduino MegaADK"},
{"name": "Arduino Leonardo"},
{"name": "Arduino Leonardo Ethernet"},
{"name": "Arduino Micro"},
{"name": "Arduino Esplora"},
{"name": "Arduino Mini"},
{"name": "Arduino Ethernet"},
{"name": "Arduino Fio"},
{"name": "Arduino BT"},
{"name": "Arduino LilyPadUSB"},
{"name": "Arduino Lilypad"},
{"name": "Arduino Pro"},
{"name": "Arduino ATMegaNG"},
{"name": "Arduino Robot Control"},
{"name": "Arduino Robot Motor"},
{"name": "Arduino Gemma"},
{"name": "Adafruit Circuit Playground"},
{"name": "Arduino Yún Mini"},
{"name": "Arduino Industrial 101"},
{"name": "Linino One"}
],
"toolsDependencies": [
{
"packager": "arduino",
"name": "avr-gcc",
"version": "4.9.2-atmel3.5.4-arduino2"
},
{
"packager": "arduino",
"name": "avrdude",
"version": "6.3.0-arduino9"
},
{
"packager": "arduino",
"name": "arduinoOTA",
"version": "1.1.1"
}
]
}
],
"tools": [
]
}
]
}

View File

@@ -316,7 +316,7 @@ void SoftwareSerial::begin(long speed)
_tx_delay = subtract_cap(bit_delay, 15 / 4);
// Only setup rx when we have a valid PCINT for this pin
if (digitalPinToPCICR(_receivePin)) {
if (digitalPinToPCICR((int8_t)_receivePin)) {
#if GCC_VERSION > 40800
// Timings counted from gcc 4.8.2 output. This works up to 115200 on
// 16Mhz and 57600 on 8Mhz.
@@ -357,7 +357,7 @@ void SoftwareSerial::begin(long speed)
// Enable the PCINT for the entire port here, but never disable it
// (others might also need it, so we disable the interrupt by using
// the per-pin PCMSK register).
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
*digitalPinToPCICR((int8_t)_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
// Precalculate the pcint mask register and value, so setRxIntMask
// can be used inside the ISR without costing too much time.
_pcint_maskreg = digitalPinToPCMSK(_receivePin);

View File

@@ -111,13 +111,4 @@ public:
static inline void handle_interrupt() __attribute__((__always_inline__));
};
// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round
#endif

View File

@@ -0,0 +1,75 @@
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
++nDevices;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // Wait 5 seconds for next scan
}

View File

@@ -18,6 +18,7 @@
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
Modified 2017 by Chuck Todd (ctodd@cableone.net) to correct Unconfigured Slave Mode reboot
Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
extern "C" {
@@ -86,6 +87,52 @@ void TwoWire::setClock(uint32_t clock)
twi_setFrequency(clock);
}
/***
* Sets the TWI timeout.
*
* This limits the maximum time to wait for the TWI hardware. If more time passes, the bus is assumed
* to have locked up (e.g. due to noise-induced glitches or faulty slaves) and the transaction is aborted.
* Optionally, the TWI hardware is also reset, which can be required to allow subsequent transactions to
* succeed in some cases (in particular when noise has made the TWI hardware think there is a second
* master that has claimed the bus).
*
* When a timeout is triggered, a flag is set that can be queried with `getWireTimeoutFlag()` and is cleared
* when `clearWireTimeoutFlag()` or `setWireTimeoutUs()` is called.
*
* Note that this timeout can also trigger while waiting for clock stretching or waiting for a second master
* to complete its transaction. So make sure to adapt the timeout to accomodate for those cases if needed.
* A typical timeout would be 25ms (which is the maximum clock stretching allowed by the SMBus protocol),
* but (much) shorter values will usually also work.
*
* In the future, a timeout will be enabled by default, so if you require the timeout to be disabled, it is
* recommended you disable it by default using `setWireTimeoutUs(0)`, even though that is currently
* the default.
*
* @param timeout a timeout value in microseconds, if zero then timeout checking is disabled
* @param reset_with_timeout if true then TWI interface will be automatically reset on timeout
* if false then TWI interface will not be reset on timeout
*/
void TwoWire::setWireTimeout(uint32_t timeout, bool reset_with_timeout){
twi_setTimeoutInMicros(timeout, reset_with_timeout);
}
/***
* Returns the TWI timeout flag.
*
* @return true if timeout has occured since the flag was last cleared.
*/
bool TwoWire::getWireTimeoutFlag(void){
return(twi_manageTimeoutFlag(false));
}
/***
* Clears the TWI timeout flag.
*/
void TwoWire::clearWireTimeoutFlag(void){
twi_manageTimeoutFlag(true);
}
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
{
if (isize > 0) {

View File

@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#ifndef TwoWire_h
@@ -54,13 +55,16 @@ class TwoWire : public Stream
void begin(int);
void end();
void setClock(uint32_t);
void setWireTimeout(uint32_t timeout = 25000, bool reset_with_timeout = false);
bool getWireTimeoutFlag(void);
void clearWireTimeoutFlag(void);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
uint8_t endTransmission(uint8_t);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
uint8_t requestFrom(int, int);
uint8_t requestFrom(int, int, int);
virtual size_t write(uint8_t);

View File

@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#include <math.h>
@@ -24,8 +25,9 @@
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <compat/twi.h>
#include "Arduino.h" // for digitalWrite
#include "Arduino.h" // for digitalWrite and micros
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@@ -43,6 +45,16 @@ static volatile uint8_t twi_slarw;
static volatile uint8_t twi_sendStop; // should the transaction end with a stop
static volatile uint8_t twi_inRepStart; // in the middle of a repeated start
// twi_timeout_us > 0 prevents the code from getting stuck in various while loops here
// if twi_timeout_us == 0 then timeout checking is disabled (the previous Wire lib behavior)
// at some point in the future, the default twi_timeout_us value could become 25000
// and twi_do_reset_on_timeout could become true
// to conform to the SMBus standard
// http://smbus.org/specs/SMBus_3_1_20180319.pdf
static volatile uint32_t twi_timeout_us = 0ul;
static volatile bool twi_timed_out_flag = false; // a timeout has been seen
static volatile bool twi_do_reset_on_timeout = false; // reset the TWI registers on timeout
static void (*twi_onSlaveTransmit)(void);
static void (*twi_onSlaveReceive)(uint8_t*, int);
@@ -154,8 +166,12 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
}
// wait until twi is ready, become master receiver
uint32_t startMicros = micros();
while(TWI_READY != twi_state){
continue;
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return 0;
}
}
twi_state = TWI_MRX;
twi_sendStop = sendStop;
@@ -183,28 +199,38 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent ourselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
startMicros = micros();
do {
TWDR = twi_slarw;
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return 0;
}
} while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
}
else
} else {
// send start condition
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);
// wait for read operation to complete
while(TWI_MRX == twi_state){
continue;
}
if (twi_masterBufferIndex < length)
// wait for read operation to complete
startMicros = micros();
while(TWI_MRX == twi_state){
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return 0;
}
}
if (twi_masterBufferIndex < length) {
length = twi_masterBufferIndex;
}
// copy twi buffer to data
for(i = 0; i < length; ++i){
data[i] = twi_masterBuffer[i];
}
return length;
}
@@ -222,6 +248,7 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
* 2 .. address send, NACK received
* 3 .. data send, NACK received
* 4 .. other twi error (lost bus arbitration, bus error, ..)
* 5 .. timeout
*/
uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
{
@@ -233,8 +260,12 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
}
// wait until twi is ready, become master transmitter
uint32_t startMicros = micros();
while(TWI_READY != twi_state){
continue;
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return (5);
}
}
twi_state = TWI_MTX;
twi_sendStop = sendStop;
@@ -265,18 +296,27 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent outselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
startMicros = micros();
do {
TWDR = twi_slarw;
TWDR = twi_slarw;
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return (5);
}
} while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
}
else
} else {
// send start condition
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA); // enable INTs
}
// wait for write operation to complete
startMicros = micros();
while(wait && (TWI_MTX == twi_state)){
continue;
if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
twi_handleTimeout(twi_do_reset_on_timeout);
return (5);
}
}
if (twi_error == 0xFF)
@@ -356,7 +396,7 @@ void twi_reply(uint8_t ack)
if(ack){
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
}else{
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
}
}
@@ -373,8 +413,19 @@ void twi_stop(void)
// wait for stop condition to be exectued on bus
// TWINT is not set after a stop condition!
// We cannot use micros() from an ISR, so approximate the timeout with cycle-counted delays
const uint8_t us_per_loop = 8;
uint32_t counter = (twi_timeout_us + us_per_loop - 1)/us_per_loop; // Round up
while(TWCR & _BV(TWSTO)){
continue;
if(twi_timeout_us > 0ul){
if (counter > 0ul){
_delay_us(us_per_loop);
counter--;
} else {
twi_handleTimeout(twi_do_reset_on_timeout);
return;
}
}
}
// update twi state
@@ -396,6 +447,59 @@ void twi_releaseBus(void)
twi_state = TWI_READY;
}
/*
* Function twi_setTimeoutInMicros
* Desc set a timeout for while loops that twi might get stuck in
* Input timeout value in microseconds (0 means never time out)
* Input reset_with_timeout: true causes timeout events to reset twi
* Output none
*/
void twi_setTimeoutInMicros(uint32_t timeout, bool reset_with_timeout){
twi_timed_out_flag = false;
twi_timeout_us = timeout;
twi_do_reset_on_timeout = reset_with_timeout;
}
/*
* Function twi_handleTimeout
* Desc this gets called whenever a while loop here has lasted longer than
* twi_timeout_us microseconds. always sets twi_timed_out_flag
* Input reset: true causes this function to reset the twi hardware interface
* Output none
*/
void twi_handleTimeout(bool reset){
twi_timed_out_flag = true;
if (reset) {
// remember bitrate and address settings
uint8_t previous_TWBR = TWBR;
uint8_t previous_TWAR = TWAR;
// reset the interface
twi_disable();
twi_init();
// reapply the previous register values
TWAR = previous_TWAR;
TWBR = previous_TWBR;
}
}
/*
* Function twi_manageTimeoutFlag
* Desc returns true if twi has seen a timeout
* optionally clears the timeout flag
* Input clear_flag: true if we should reset the hardware
* Output none
*/
bool twi_manageTimeoutFlag(bool clear_flag){
bool flag = twi_timed_out_flag;
if (clear_flag){
twi_timed_out_flag = false;
}
return(flag);
}
ISR(TWI_vect)
{
switch(TW_STATUS){
@@ -416,16 +520,16 @@ ISR(TWI_vect)
TWDR = twi_masterBuffer[twi_masterBufferIndex++];
twi_reply(1);
}else{
if (twi_sendStop)
if (twi_sendStop){
twi_stop();
else {
twi_inRepStart = true; // we're gonna send the START
// don't enable the interrupt. We'll generate the start, but we
// avoid handling the interrupt until we're in the next transaction,
// at the point where we would normally issue the start.
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
twi_state = TWI_READY;
}
} else {
twi_inRepStart = true; // we're gonna send the START
// don't enable the interrupt. We'll generate the start, but we
// avoid handling the interrupt until we're in the next transaction,
// at the point where we would normally issue the start.
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
twi_state = TWI_READY;
}
}
break;
case TW_MT_SLA_NACK: // address sent, nack received
@@ -445,6 +549,7 @@ ISR(TWI_vect)
case TW_MR_DATA_ACK: // data received, ack sent
// put byte into buffer
twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
__attribute__ ((fallthrough));
case TW_MR_SLA_ACK: // address sent, ack received
// ack if more bytes are expected, otherwise nack
if(twi_masterBufferIndex < twi_masterBufferLength){
@@ -456,17 +561,17 @@ ISR(TWI_vect)
case TW_MR_DATA_NACK: // data received, nack sent
// put final byte into buffer
twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
if (twi_sendStop)
twi_stop();
else {
twi_inRepStart = true; // we're gonna send the START
// don't enable the interrupt. We'll generate the start, but we
// avoid handling the interrupt until we're in the next transaction,
// at the point where we would normally issue the start.
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
twi_state = TWI_READY;
}
break;
if (twi_sendStop){
twi_stop();
} else {
twi_inRepStart = true; // we're gonna send the START
// don't enable the interrupt. We'll generate the start, but we
// avoid handling the interrupt until we're in the next transaction,
// at the point where we would normally issue the start.
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
twi_state = TWI_READY;
}
break;
case TW_MR_SLA_NACK: // address sent, nack received
twi_stop();
break;
@@ -530,6 +635,7 @@ ISR(TWI_vect)
twi_txBufferLength = 1;
twi_txBuffer[0] = 0x00;
}
__attribute__ ((fallthrough));
// transmit first byte from buffer, fall
case TW_ST_DATA_ACK: // byte sent, ack returned
// copy data to output register
@@ -558,4 +664,3 @@ ISR(TWI_vect)
break;
}
}

View File

@@ -15,6 +15,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#ifndef twi_h
@@ -50,6 +52,8 @@
void twi_reply(uint8_t);
void twi_stop(void);
void twi_releaseBus(void);
void twi_setTimeoutInMicros(uint32_t, bool);
void twi_handleTimeout(bool);
bool twi_manageTimeoutFlag(bool);
#endif

View File

@@ -6,7 +6,7 @@
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
name=Arduino AVR Boards
version=1.6.23
version=1.8.3
# AVR compile variables
# ---------------------
@@ -33,6 +33,7 @@ compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,
compiler.elf2hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=avr-objcopy
compiler.ldflags=
compiler.libraries.ldflags=
compiler.size.cmd=avr-size
# This can be overridden in boards.txt
@@ -65,7 +66,7 @@ archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} "{build.path}/{archive_file}" "-L{build.path}" -lm
## Create output files (.eep and .hex)
recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"

View File

@@ -43,13 +43,22 @@ parallel.program.extra_params=-F
arduinoasisp.name=Arduino as ISP
arduinoasisp.communication=serial
arduinoasisp.protocol=arduino
arduinoasisp.protocol=stk500v1
arduinoasisp.speed=19200
arduinoasisp.program.protocol=arduino
arduinoasisp.program.protocol=stk500v1
arduinoasisp.program.speed=19200
arduinoasisp.program.tool=avrdude
arduinoasisp.program.extra_params=-P{serial.port} -b{program.speed}
arduinoasispatmega32u4.name=Arduino as ISP (ATmega32U4)
arduinoasispatmega32u4.communication=serial
arduinoasispatmega32u4.protocol=arduino
arduinoasispatmega32u4.speed=19200
arduinoasispatmega32u4.program.protocol=arduino
arduinoasispatmega32u4.program.speed=19200
arduinoasispatmega32u4.program.tool=avrdude
arduinoasispatmega32u4.program.extra_params=-P{serial.port} -b{program.speed}
usbGemma.name=Arduino Gemma
usbGemma.protocol=arduinogemma
usbGemma.program.tool=avrdude

View File

@@ -250,5 +250,6 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
// pins are NOT connected to anything by default.
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#define SERIAL_PORT_MONITOR Serial
#endif