From: Ace Date: Fri, 14 Dec 2018 12:02:53 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/ChangeLog.html?a=commitdiff_plain;h=5ab1eefb2f76a55aa67422035f073b87726cf9af;p=acecode.git ... --- diff --git a/arduino/Fm.ino b/arduino/Fm.ino deleted file mode 100644 index 844b2e9..0000000 --- a/arduino/Fm.ino +++ /dev/null @@ -1,38 +0,0 @@ -int fmpin=12; //设置蜂鸣器数字接口1 -void setup() -{ - pinMode(fmpin,OUTPUT); -} - -void fm(float f) -{ - float T = (float) ((float)1000000) / f; - - int d = (int) (T/2); - - int cnt = 1*(int)f; - - int i; - for(i=0; i - - -void setup() -{ - Wire.begin(); - - Serial.begin(9600); - Serial.println("\nI2C Scanner"); -} - - -void loop() -{ - byte error, address; - int nDevices; - - Serial.println("Scanning..."); - - nDevices = 0; - for(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); - 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("Unknow 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 -} diff --git a/arduino/IR.Recv.ino b/arduino/IR.Recv.ino deleted file mode 100644 index 7ad22d8..0000000 --- a/arduino/IR.Recv.ino +++ /dev/null @@ -1,22 +0,0 @@ -#include - -int RECV_PIN = 11; - -IRrecv irrecv(RECV_PIN); - -decode_results results; - -void setup() -{ - Serial.begin(9600); - irrecv.enableIRIn(); -} - -void loop() -{ - if(irrecv.decode(&results)) { - Serial.println(results.value, HEX); - Serial.println(); - irrecv.resume(); - } -} diff --git a/arduino/IR.Send.ino b/arduino/IR.Send.ino deleted file mode 100644 index 70e9748..0000000 --- a/arduino/IR.Send.ino +++ /dev/null @@ -1,77 +0,0 @@ -/* -* 发射红外线信号 -* 注意! 红外线发射器(IR LED)必须接到 pin 3, 不能接其它脚位 - - Hisense 机顶盒 SD-16127 tested - */ - -//By Leo 2013.02.19 -//http://weibo.com/leolite -//Update: Pin 3 IR LED test function - - -#include // 引用 IRRemote 函式库 - -int RECV_PIN = 11; -IRrecv irrecv(RECV_PIN); - -IRsend irsend; // 定义 IRsend 物件来发射红外线讯号 -decode_results results; - - -void setup() -{ - Serial.begin(9600); - pinMode(3,OUTPUT); - /* - irrecv.enableIRIn(); - - pinMode(3, OUTPUT); - digitalWrite(3, HIGH); // 点亮LED测试(需通过手机摄像模式观察) - delay(3000); // 等待3秒 - digitalWrite(3, LOW); // 结束测试*/ -} - -void showIRProtocol(decode_results *results) -{ - Serial.print("Protocol: "); - - // 判断红外线协定种类 - switch(results->decode_type) { - case NEC: - Serial.print("NEC"); - break; - case SONY: - Serial.print("SONY"); - break; - case RC5: - Serial.print("RC5"); - break; - case RC6: - Serial.print("RC6"); - break; - default: - Serial.print("Unknown encoding"); - } - - // 把红外线编码印到 Serial port - Serial.print(", irCode: "); - Serial.print(results->value, HEX); // 红外线编码 - Serial.print(", bits: "); - Serial.println(results->bits); // 红外线编码位元数 -} - -void loop() -{ - //Serial.print("SendIR: "); - //irsend.sendNEC(0x807FE01F, 32); // 记得换成你遥控器的红外线编码 - //delay(100); // 等待3秒 - - if(irrecv.decode(&results)) { - //Serial.println(results.value, HEX); - //Serial.println(); - showIRProtocol(&results); - irrecv.resume(); - } -} - diff --git a/arduino/InfraredReceiver.ino b/arduino/InfraredReceiver.ino deleted file mode 100644 index 231e047..0000000 --- a/arduino/InfraredReceiver.ino +++ /dev/null @@ -1,30 +0,0 @@ -//本例来自于红外接收模块的IRremote自带范例 -/* - * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv - * An IR detector/demodulator must be connected to the input RECV_PIN. - * Version 0.1 July, 2009 - * Copyright 2009 Ken Shirriff - * [url]http://arcfn.com[/url] - */ - -#include - -int RECV_PIN = 11;//定义红外接收器的引脚为11 -IRrecv irrecv(RECV_PIN); -decode_results results; - -void setup() -{ - Serial.begin(9600); - irrecv.enableIRIn(); // 初始化红外接收器 -} - -void loop() { - //Serial.println("HAHA"); - if (irrecv.decode(&results)) { - Serial.println(results.value, HEX);//以16进制换行输出接收代码 - Serial.println();//为了便于观看输出结果增加一个空行 - irrecv.resume(); // 接收下一个值 - } -} - diff --git a/arduino/README.md b/arduino/README.md new file mode 100644 index 0000000..d18661f --- /dev/null +++ b/arduino/README.md @@ -0,0 +1,6 @@ +Arduino IDE > Arduino Menu > Preferences > Settings > Setchbook location + +ArduinoPath = $HOME/workspace/Arduino + +cd $ArduinoPath +ln -s "this dir" AceArduino diff --git a/arduino/Sensors/Sensors.ino b/arduino/Sensors/Sensors.ino deleted file mode 100644 index 81f45aa..0000000 --- a/arduino/Sensors/Sensors.ino +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include - -#define TEMP_WIRE_BUS 2 - -OneWire TempWire(TEMP_WIRE_BUS); -DallasTemperature TempSensors(&TempWire); - - -SoftwareSerial BTSerial(10, 11); // RX | TX - - -DHT dht; - -int cnt = 0; -const int ledPin = 12; - -void setup() { - Serial.begin(9600); - BTSerial.begin(9600); // HC-06 current bound rate (default 9600) - pinMode(ledPin, OUTPUT); - pinMode(0, INPUT); - pinMode(1, INPUT); - pinMode(2, INPUT); - pinMode(3, INPUT); - - TempSensors.begin();//TEMP_WIRE_BUS); - TempSensors.setResolution(12); - - dht.setup(4, DHT::DHT11); -} - -char *itos(int n) -{ - static char buf[16]; - sprintf(buf, "%d", n); - return buf; -} - -char *ftos(float f) -{ - static char buf[32]; - sprintf(buf, "%.2f", f); - return buf; -} - -void loop() { - cnt ++; -#if 0 - int bd = digitalRead(7); - - Serial.print(">"); - Serial.print(bd); - Serial.println("<"); - delay(100); - return; -#endif - - TempSensors.requestTemperatures(); - float tv = TempSensors.getTempCByIndex(0); - - //delay(dht.getMinimumSamplingPeriod()); - float hv = dht.getHumidity(); // Humidity - - int lv = analogRead(0); // Light - - //int tv = analogRead(1); // Temperature - - int hb = analogRead(2); // Human Body - - //int hv = analogRead(3); // humidity - - - if(cnt % 1 == 0) - { - Serial.print(">"); - Serial.print(lv); - Serial.print(":"); - Serial.print(tv); - Serial.print(":"); - Serial.print(hb); - Serial.print(":"); - Serial.print(hv); - Serial.print(" Humidity:"); - Serial.print(dht.getHumidity()); - Serial.print(" Temp:"); - Serial.print(dht.getTemperature()); - Serial.println(" "); - - -#if 1 - BTSerial.print(">"); - BTSerial.print(lv, DEC); - BTSerial.print(":"); - BTSerial.print(tv, DEC); - BTSerial.print(":"); - BTSerial.print(hv, DEC); - BTSerial.print(":"); - BTSerial.print(hb, DEC); - BTSerial.println("<"); -#endif - - -#if 0 - BTSerial.write(">"); - BTSerial.write(itos(lv)); - BTSerial.write(":"); - BTSerial.write(ftos(tv)); - BTSerial.write(":"); - BTSerial.write(itos(hb)); - BTSerial.write(":"); - BTSerial.write(itos(hv)); - BTSerial.write("\n"); -#endif - - } -} - diff --git a/arduino/Servo.ino b/arduino/Servo.ino deleted file mode 100644 index 2dc9b84..0000000 --- a/arduino/Servo.ino +++ /dev/null @@ -1,62 +0,0 @@ -#include - -Servo myservo; // create servo object to control a servo - // a maximum of eight servo objects can be created - -const int RLedPin = 11; -const int BLedPin = 12; -void setup() -{ - Serial.begin(9600); - pinMode(RLedPin, OUTPUT); - pinMode(BLedPin, OUTPUT); - myservo.attach(9); // attaches the servo on pin 9 to the servo object -} - -int pos = 0; -int last_pos = 0; - -void loop() -{ - int lv = analogRead(0); // Light - int sign = 1; - if(lv < 400) - { - sign = -1; - } - - int st = sign * 10; - - pos += st; - - if(pos <= 30) pos = 30; - if(pos >= 120) pos = 120; - - if(pos != last_pos) - { - if(sign == 1) - { - digitalWrite(RLedPin, HIGH); - digitalWrite(BLedPin, LOW); - } - else - { - digitalWrite(RLedPin, LOW); - digitalWrite(BLedPin, HIGH); - } - Serial.print("<> pos"); - Serial.println(pos); - myservo.write(pos); - delay(15); - } - else - { - - digitalWrite(RLedPin, LOW); - digitalWrite(BLedPin, LOW); - Serial.print("== pos"); - Serial.println(pos); - } - - last_pos = pos; -} diff --git a/arduino/Stickers.png b/arduino/Stickers.png deleted file mode 100755 index 95b5163..0000000 Binary files a/arduino/Stickers.png and /dev/null differ diff --git a/arduino/UltrasonicSensor.ino b/arduino/UltrasonicSensor.ino deleted file mode 100644 index 4290a8f..0000000 --- a/arduino/UltrasonicSensor.ino +++ /dev/null @@ -1,30 +0,0 @@ -const int TrigPin = 2; // 2 -const int EchoPin = 3; // ~3 - -float dist; - -void setup() -{ - Serial.begin(9600); - pinMode(TrigPin, OUTPUT); - pinMode(EchoPin, INPUT); - Serial.println("Ultrasonic Sensor:"); -} - -void loop() -{ - digitalWrite(TrigPin, LOW); - delayMicroseconds(2); - digitalWrite(TrigPin, HIGH); - delayMicroseconds(10); - digitalWrite(TrigPin, LOW); - - // distance = (HIGH_TIME*(340m/s))/2; - // pulseIn get us - // distance = ((pulseIn/10E6)*340/2)*100 - dist = pulseIn(EchoPin, HIGH) * 17 / 1000; - - Serial.print(dist); - Serial.println("cm"); - delay(100); -} diff --git a/arduino/bluetoothinit.ino b/arduino/bluetoothinit.ino deleted file mode 100644 index 31d492d..0000000 --- a/arduino/bluetoothinit.ino +++ /dev/null @@ -1,17 +0,0 @@ -#include -SoftwareSerial BTSerial(10, 11); // RX | TX -void setup() -{ - Serial.begin(9600); - Serial.println("Enter AT commands:"); - BTSerial.begin(9600); // HC-06 current bound rate (default 9600) -} -void loop() -{ - // Keep reading from HC-06 and send to Arduino Serial Monitor - if (BTSerial.available()) - Serial.write(BTSerial.read()); - // Keep reading from Arduino Serial Monitor and send to HC-06 - if (Serial.available()) - BTSerial.write(Serial.read()); -} diff --git a/arduino/clockintr/clockintr.ino b/arduino/clockintr/clockintr.ino deleted file mode 100644 index 25f0363..0000000 --- a/arduino/clockintr/clockintr.ino +++ /dev/null @@ -1,96 +0,0 @@ - -int led0 = 7; -int led1 = 8; -int led2 = 12; -int cnt0 = 0; -int cnt1 = 0; -int cnt2 = 0; -void setup(){ - Serial.begin(9600); - pinMode(LED_BUILTIN, OUTPUT); - pinMode(led0, OUTPUT); - pinMode(led1, OUTPUT); - pinMode(led2, OUTPUT); - - cli();//stop interrupts - -#if 0 // 设置timer0会影响到loop函数里调用的delay,会使其失效 - //set timer0 interrupt at 2kHz - TCCR0A = 0;// set entire TCCR0A register to 0 - TCCR0B = 0;// same for TCCR0B - TCNT0 = 0;//initialize counter value to 0 - // set compare match register for 2khz increments - OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256) - // turn on CTC mode - TCCR0A |= (1 << WGM01); - // Set CS01 and CS00 bits for 64 prescaler (参考上表) - TCCR0B |= (1 << CS01) | (1 << CS00); - // enable timer compare interrupt - TIMSK0 |= (1 << OCIE0A); -#endif - -#if 1 - //set timer1 interrupt at 1Hz - TCCR1A = 0;// set entire TCCR1A register to 0 - TCCR1B = 0;// same for TCCR1B - TCNT1 = 0;//initialize counter value to 0 - // set compare match register for 1hz increments - OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536) - // turn on CTC mode - TCCR1B |= (1 << WGM12); - // Set CS10 and CS12 bits for 1024 prescaler (参考上表) - TCCR1B |= (1 << CS12) | (1 << CS10); - // enable timer compare interrupt - TIMSK1 |= (1 << OCIE1A); -#endif - -#if 1 - //set timer2 interrupt at 8kHz - TCCR2A = 0;// set entire TCCR2A register to 0 - TCCR2B = 0;// same for TCCR2B - TCNT2 = 0;//initialize counter value to 0 - // set compare match register for 8khz increments - OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256) - // turn on CTC mode - TCCR2A |= (1 << WGM21); - // Set CS21 bit for 8 prescaler (参考上表) - TCCR2B |= (1 << CS21); - // enable timer compare interrupt - TIMSK2 |= (1 << OCIE2A); -#endif - - sei();//allow interrupts - -}//end setup - -void loop() { - Serial.println("High"); - digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) - delay(1000); // wait for a second - - Serial.println("Low"); - digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW - delay(1000); // wait for a second -} - -ISR(TIMER0_COMPA_vect){ - cnt0++; - if(cnt0 % 1000 == 0) { - cnt0 == 0; - digitalWrite(led0, !digitalRead(led0)); - } -} - -ISR(TIMER1_COMPA_vect){ - cnt1++; - digitalWrite(led1, !digitalRead(led1)); -} - -ISR(TIMER2_COMPA_vect) { - cnt2++; - if(cnt2 % 1000 == 0) { - cnt2 = 0; - digitalWrite(led2, !digitalRead(led2)); - } -} - diff --git a/arduino/hardware/ArduinoIDE_1.5_3rd_party_hardware_specification.md b/arduino/hardware/ArduinoIDE_1.5_3rd_party_hardware_specification.md deleted file mode 100644 index a5e1781..0000000 --- a/arduino/hardware/ArduinoIDE_1.5_3rd_party_hardware_specification.md +++ /dev/null @@ -1,550 +0,0 @@ -This specification is a 3rd party Hardware format to be used in Arduino IDE starting from 1.5.x series. \ -This specification allows a 3rd party vendor/maintainer to add support for new boards inside the Arduino IDE by providing a file to unzip into the *hardware* folder of Arduino's sketchbook folder. \ -It is also possible to add new 3rd party boards by providing just one configuration file. - -# Hardware Folders structure - -The new hardware folders have a hierarchical structure organized in two levels: - - the first level is the vendor/maintainer - - the second level is the supported architecture - -A vendor/maintainer can have multiple supported architectures. For example, below we have three hardware vendors called "arduino", "yyyyy" and "xxxxx": - - hardware/arduino/avr/... - Arduino - AVR Boards - hardware/arduino/sam/... - Arduino - SAM (32bit ARM) Boards - hardware/yyyyy/avr/... - Yyy - AVR - hardware/xxxxx/avr/... - Xxx - AVR - -The vendor "arduino" has two supported architectures (AVR and SAM), while "xxxxx" and "yyyyy" have only AVR. - -# Architecture configurations - -Each architecture must be configured through a set of configuration files: - -- **platform.txt** contains definitions for the CPU architecture used (compiler, build process parameters, tools used for upload, etc.) -- **boards.txt** contains definitions for the boards (board name, parameters for building and uploading sketches, etc.) -- **programmers.txt** contains definitions for external programmers (typically used to burn bootloaders or sketches on a blank CPU/board) - -## Configuration files format - -A configuration file is a list of "key=value" properties. The **value** of a property can be expressed using the value of another property by putting its name inside brackets "{" "}". For example: - - compiler.path=/tools/g++_arm_none_eabi/bin/ - compiler.c.cmd=arm-none-eabi-gcc - [....] - recipe.c.o.pattern={compiler.path}{compiler.c.cmd} - -In this example the property **recipe.c.o.pattern** will be set to **/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc** that is the composition of the two properties **compiler.path** and **compiler.c.cmd**. - -### Comments - -Lines starting with **#** are treated as comments and will be ignored. - - # Like in this example - # -------------------- - # I'm a comment! - -### Automatic property override for specific OS - -We can specify an OS-specific value for a property. For example the following file: - - tools.bossac.cmd=bossac - tools.bossac.cmd.windows=bossac.exe - -will set the property **tools.bossac.cmd** to the value **bossac** on Linux and Mac OS and **bossac.exe** on Windows. - -### Global Predefined properties - -The Arduino IDE sets the following properties that can be used globally in all configurations files: - - {runtime.platform.path} - the absolute path of the platform folder (i.e. the folder containing boards.txt) - {runtime.hardware.path} - the absolute path of the hardware folder (i.e. the folder containing the current platform folder) - {runtime.ide.path} - the absolute path of the Arduino IDE folder - {runtime.ide.version} - the version number of the Arduino IDE as a number (this uses two digits per version - number component, and removes the points and leading zeroes, so Arduino IDE 1.8.3 - becomes 01.08.03 which becomes runtime.ide.version=10803). - {ide_version} - Compatibility alias for {runtime.ide.version} - {runtime.os} - the running OS ("linux", "windows", "macosx") - -Compatibility note: Versions before 1.6.0 only used one digit per version number component in `{runtime.ide.version}` -(so 1.5.9 was 159, not 10509). - -# platform.txt - -The platform.txt file contains information about a platform's specific aspects (compilers -command line flags, paths, system libraries, etc.). - -The following meta-data must be defined: - - name=Arduino AVR Boards - version=1.5.3 - -The **name** will be shown in the Boards menu of the Arduino IDE. \ -The **version** is currently unused, it is reserved for future use (probably together with the libraries manager to handle dependencies on cores). - -## Build process - -The platform.txt file is used to configure the build process performed by the Arduino IDE. This is done through a list of **recipes**. Each recipe is a command line expression that explains how to call the compiler (or other tools) for every build step and which parameter should be passed. - -The Arduino IDE, before starting the build, determines the list of files to compile. The list is composed by: -- the user's Sketch -- source code in the selected board's Core -- source code in the Libraries used in the sketch - -The IDE creates a temporary folder to store the build artifacts whose path is available through the global property **{build.path}**. A property **{build.project_name}** with the name of the project and a property **{build.arch}** with the name of the architecture is set as well. - - {build.path} - The path to the temporary folder to store build artifacts - {build.project_name} - The project name - {build.arch} - The MCU architecture (avr, sam, etc...) - -There are some other **{build.xxx}** properties available, that are explained in the boards.txt section of this guide. - -### Recipes to compile source code - -We said that the Arduino IDE determines a list of files to compile. Each file can be source code written in C (.c files), C++ (.cpp files) or Assembly (.S files). Every language is compiled using its respective **recipe**: - - recipe.c.o.pattern - for C files - recipe.cpp.o.pattern - for CPP files - recipe.S.o.pattern - for Assembly files - -The recipes can be built concatenating other properties set by the IDE (for each file compiled): - - {includes} - the list of include paths in the format "-I/include/path -I/another/path...." - {source_file} - the path to the source file - {object_file} - the path to the output file - -For example the following is used for AVR: - - ## Compiler global definitions - compiler.path={runtime.ide.path}/tools/avr/bin/ - compiler.c.cmd=avr-gcc - compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD - - [......] - - ## Compile c files - recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" - -Note that some properties, like **{build.mcu}** for example, are taken from the **boards.txt** file which is documented later in this specification. - -### Recipes to build the core.a archive file - -The core of the selected board is compiled as described in the previous paragraph, but the object files obtained from the compile are also archived into a static library named *core.a* using the **recipe.ar.pattern**. - -The recipe can be built concatenating the following properties set by the IDE: - - {object_file} - the object file to include in the archive - {archive_file_path} - fully qualified archive file (ex. "/path/to/core.a"). This property was added in Arduino IDE 1.6.6/arduino builder 1.0.0-beta12 as a replacement for {build.path}/{archive_file}. - {archive_file} - the name of the resulting archive (ex. "core.a") - -For example, Arduino provides the following for AVR: - - compiler.ar.cmd=avr-ar - compiler.ar.flags=rcs - - [......] - - ## Create archives - recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}" - -### Recipes for linking - -All the artifacts produced by the previous steps (sketch object files, libraries object files and core.a archive) are linked together using the **recipe.c.combine.pattern**. - -The recipe can be built concatenating the following properties set by the IDE: - - {object_files} - the list of object files to include in the archive ("file1.o file2.o ....") - {archive_file_path} - fully qualified archive file (ex. "/path/to/core.a"). This property was added in Arduino IDE 1.6.6/arduino builder 1.0.0-beta12 as a replacement for {build.path}/{archive_file}. - {archive_file} - the name of the core archive file (ex. "core.a") - -For example the following is used for AVR: - - compiler.c.elf.flags=-Os -Wl,--gc-sections - compiler.c.elf.cmd=avr-gcc - - [......] - - ## Combine gc-sections, archives, and objects - recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{archive_file_path}" "-L{build.path}" -lm - -### Recipes for extraction of executable files and other binary data - -An arbitrary number of extra steps can be performed by the IDE at the end of objects linking. -These steps can be used to extract binary data used for upload and they are defined by a set of recipes with the following format: - - recipe.objcopy.FILE_EXTENSION_1.pattern=[.....] - recipe.objcopy.FILE_EXTENSION_2.pattern=[.....] - [.....] - -`FILE_EXTENSION_x` must be replaced with the extension of the extracted file, for example the AVR platform needs two files a `.hex` and a `.eep`, so we made two recipes like: - - recipe.objcopy.eep.pattern=[.....] - recipe.objcopy.hex.pattern=[.....] - -There are no specific properties set by the IDE here. -A full example for the AVR platform can be: - - ## Create eeprom - recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" - - ## Create hex - recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" - -### Recipes to compute binary sketch size - -At the end of the build the Arduino IDE shows the final binary sketch size to the user. The size is calculated using the recipe **recipe.size.pattern**. The output of the command executed using the recipe is parsed through the regular expression set in the property **recipe.size.regex**. The regular expression must match the sketch size. - -For AVR we have: - - compiler.size.cmd=avr-size - [....] - ## Compute size - recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.hex" - recipe.size.regex=Total\s+([0-9]+).* - -### Recipe to run the preprocessor -For detecting what libraries to include in the build, and for generating function prototypes, the Arduino IDE must be able to run (just) the preprocessor. For this, the **recipe.preproc.macros** recipe exists. This recipe must run the preprocessor on a given source file, writing the preprocessed output to a given output file, and generate (only) preprocessor errors on standard output. This preprocessor run should happen with the same defines and other preprocessor-influencing-options as for normally compiling the source files. - -The recipes can be built concatenating other properties set by the IDE (for each file compiled): - - {includes} - the list of include paths in the format "-I/include/path -I/another/path...." - {source_file} - the path to the source file - {preprocessed_file_path} - the path to the output file - -For example the following is used for AVR: - - preproc.macros.flags=-w -x c++ -E -CC - recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{preprocessed_file_path}" - -Note that the `{preprocessed_file_path}` might point to (your platform's equivalent) of `/dev/null`. In this case, also passing `-MMD` to gcc is problematic, as it will try to generate a dependency file called `/dev/null.d`, which will usually result in a permission error. Since platforms typically include `{compiler.cpp.flags}` here, which includes `-MMD`, the Arduino IDE automatically filters out the `-MMD` option from the `recipe.preproc.macros` recipe to prevent this error. - -Note that older IDE versions used the **recipe.preproc.includes** recipe to determine includes, which is undocumented here. Since Arduino IDE 1.6.7 (arduino-builder 1.2.0) this was changed and **recipe.preproc.includes** is no longer used. - -### Pre and post build hooks (since IDE 1.6.5) - -You can specify pre and post actions around each recipe. These are called "hooks". Here is the complete list of available hooks: -* `recipe.hooks.sketch.prebuild.NUMBER.pattern` (called before sketch compilation) -* `recipe.hooks.sketch.postbuild.NUMBER.pattern` (called after sketch compilation) -* `recipe.hooks.libraries.prebuild.NUMBER.pattern` (called before libraries compilation) -* `recipe.hooks.libraries.postbuild.NUMBER.pattern` (called after libraries compilation) -* `recipe.hooks.core.prebuild.NUMBER.pattern` (called before core compilation) -* `recipe.hooks.core.postbuild.NUMBER.pattern` (called after core compilation) -* `recipe.hooks.linking.prelink.NUMBER.pattern` (called before linking) -* `recipe.hooks.linking.postlink.NUMBER.pattern` (called after linking) -* `recipe.hooks.objcopy.preobjcopy.NUMBER.pattern` (called before objcopy recipes execution) -* `recipe.hooks.objcopy.postobjcopy.NUMBER.pattern` (called after objcopy recipes execution) -* `recipe.hooks.savehex.presavehex.NUMBER.pattern` (called before savehex recipe execution) -* `recipe.hooks.savehex.postsavehex.NUMBER.pattern` (called after savehex recipe execution) - -Example: you want to execute 2 commands before sketch compilation and 1 after linking. You'll add to your platform.txt -``` -recipe.hooks.sketch.prebuild.1.pattern=echo sketch compilation started at -recipe.hooks.sketch.prebuild.2.pattern=date - -recipe.hooks.linking.postlink.1.pattern=echo linking is complete -``` - -Warning: hooks recipes are sorted before execution. If you need to write more than 10 recipes for a single hook, pad the number with a zero, for example: -``` -recipe.hooks.sketch.prebuild.01.pattern=echo 1 -recipe.hooks.sketch.prebuild.02.pattern=echo 2 -... -recipe.hooks.sketch.prebuild.11.pattern=echo 11 -``` - -# platform.local.txt - -Introduced in Arduino IDE 1.5.7. This file can be used to override properties defined in platform.txt or define new properties without modifying platform.txt. - - -# boards.txt - -This file contains definitions and meta-data for the boards supported. Every board must be referred through its short name, the board ID. The settings for a board are defined through a set of properties -with keys having the board ID as prefix. - -For example the board ID chosen for the Arduino Uno board is "uno". An extract of the Uno board configuration in boards.txt looks like: - - [......] - uno.name=Arduino Uno - uno.build.mcu=atmega328p - uno.build.f_cpu=16000000L - uno.build.board=AVR_UNO - uno.build.core=arduino - uno.build.variant=standard - [......] - -Note that all the relevant keys start with the board ID **uno.xxxxx**. - -The **uno.name** property contains the name of the board shown in the Board menu of the Arduino IDE. - -The **uno.build.board** property is used to set a compile-time variable **ARDUINO_{build.board}** to allow use of conditional code between `#ifdef`s. The Arduino IDE automatically generates a **build.board** value if not defined. In this case the variable defined at compile time will be `ARDUINO_AVR_UNO`. - -The other properties will override the corresponding global properties of the IDE when the user selects the board. These properties will be globally available, in other configuration files too, without the board ID prefix: - - uno.build.mcu => build.mcu - uno.build.f_cpu => build.f_cpu - uno.build.board => build.board - uno.build.core => build.core - uno.build.variant => build.variant - -This explains the presence of **{build.mcu}** or **{build.board}** in the platform.txt recipes: their value is overwritten respectively by **{uno.build.mcu}** and **{uno.build.board}** when the Uno board is selected! -Moreover the IDE automatically provides the following properties: - - {build.core.path} - The path to the selected board's core folder - (for example hardware/arduino/avr/core/arduino) - {build.system.path} - The path to the selected platform's system folder if available - (for example hardware/arduino/sam/system) - {build.variant.path} - The path to the selected board variant folder - (for example hardware/arduino/avr/variants/micro) - -## Cores - -Cores are placed inside the **cores** subfolder. Many different cores can be provided within a single platform. For example the following could be a valid platform layout: - - hardware/arduino/avr/cores/ - Cores folder for "avr" architecture, package "arduino" - hardware/arduino/avr/cores/arduino - the Arduino Core - hardware/arduino/avr/cores/rtos - an hypothetical RTOS Core - -The board's property **build.core** is used by the Arduino IDE to find the core that must be compiled and linked when the board is selected. For example if a board needs the Arduino core the **build.core** variable should be set to: - - uno.build.core=arduino - -or if the RTOS core is needed, to: - - uno.build.core=rtos - -In any case the contents of the selected core folder are compiled and the core folder path is added to the include files search path. - -## Core Variants - -Sometimes a board needs some tweaking on default core configuration (different pin mapping is a typical example). A core variant folder is an additional folder that is compiled together with the core and allows to easily add specific configurations. - -Variants must be placed inside the **variants** folder in the current architecture. -For example, Arduino AVR Boards uses: - - hardware/arduino/avr/cores - Core folder for "avr" architecture, "arduino" package - hardware/arduino/avr/cores/arduino - The Arduino core - hardware/arduino/avr/variants/ - Variant folder for "avr" architecture, "arduino" package - hardware/arduino/avr/variants/standard - ATmega328 based variants - hardware/arduino/avr/variants/leonardo - ATmega32U4 based variants - -In this example, the Arduino Uno board needs the *standard* variant so the **build.variant** property is set to *standard*: - - [.....] - uno.build.core=arduino - uno.build.variant=standard - [.....] - -instead, the Arduino Leonardo board needs the *leonardo* variant: - - [.....] - leonardo.build.core=arduino - leonardo.build.variant=leonardo - [.....] - -In the example above, both Uno and Leonardo share the same core but use different variants. \ -In any case, the contents of the selected variant folder path is added to the include search path and its contents are compiled and linked with the sketch. - -The parameter **build.variant.path** is automatically found by the IDE. - -# Tools - -The Arduino IDE uses external command line tools to upload the compiled sketch to the board or to burn bootloaders using external programmers. Currently *avrdude* is used for AVR based boards and *bossac* for SAM based boards, but there is no limit, any command line executable can be used. The command line parameters are specified using **recipes** in the same way used for platform build process. - -Tools are configured inside the platform.txt file. Every Tool is identified by a short name, the Tool ID. -A tool can be used for different purposes: - -- **upload** a sketch to the target board (using a bootloader preinstalled on the board) -- **program** a sketch to the target board using an external programmer -- **erase** the target board's flash memory using an external programmer -- burn a **bootloader** into the target board using an external programmer - -Each action has its own recipe and its configuration is done through a set of properties having key starting with **tools** prefix followed by the tool ID and the action: - - [....] - tools.avrdude.upload.pattern=[......] - [....] - tools.avrdude.program.pattern=[......] - [....] - tools.avrdude.erase.pattern=[......] - [....] - tools.avrdude.bootloader.pattern=[......] - [.....] - -A tool may have some actions not defined (it's not mandatory to define all four actions). \ -Let's look at how the **upload** action is defined for avrdude: - - tools.avrdude.path={runtime.tools.avrdude.path} - tools.avrdude.cmd.path={path}/bin/avrdude - tools.avrdude.config.path={path}/etc/avrdude.conf - - tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" - -A **{runtime.tools.TOOL_NAME.path}** and **{runtime.tools.TOOL_NAME-TOOL_VERSION.path}** property is generated for the tools of Arduino AVR Boards and any other platform installed via Boards Manager. **{runtime.tools.TOOL_NAME.path}** points to the latest version of the tool available. - -The Arduino IDE makes the tool configuration properties available globally without the prefix. For example, the **tools.avrdude.cmd.path** property can be used as **{cmd.path}** inside the recipe, and the same happens for all the other avrdude configuration variables. - -### Verbose parameter - -It is possible for the user to enable verbosity from the Arduino IDE's Preferences panel. This preference is transferred to the command line by the IDE using the **ACTION.verbose** property (where ACTION is the action we are considering). \ -When the verbose mode is enabled the **tools.TOOL_ID.ACTION.params.verbose** property is copied into **ACTION.verbose**. When the verbose mode is disabled, the **tools.TOOL_ID.ACTION.params.quiet** property is copied into **ACTION.verbose**. Confused? Maybe an example will clear things: - - tools.avrdude.upload.params.verbose=-v -v -v -v - tools.avrdude.upload.params.quiet=-q -q - tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" - -In this example if the user enables verbose mode, then **{upload.params.verbose}** is used in **{upload.verbose}**: - - tools.avrdude.upload.params.verbose => upload.verbose - -If the user didn't enable verbose mode, the **{upload.params.quiet}** is used in **{upload.verbose}**: - - tools.avrdude.upload.params.quiet => upload.verbose - -## Sketch upload configuration - -The Upload action is triggered when the user clicks on the "Upload" button on the IDE toolbar. -The Arduino IDE selects the tool to be used for upload by looking at the **upload.tool** property. -A specific **upload.tool** property should be defined for every board in boards.txt: - - [......] - uno.upload.tool=avrdude - [......] - leonardo.upload.tool=avrdude - [......] - -Also other upload parameters can be defined together, for example in the Arduino boards.txt we have: - - [.....] - uno.name=Arduino Uno - uno.upload.tool=avrdude - uno.upload.protocol=arduino - uno.upload.maximum_size=32256 - uno.upload.speed=115200 - [.....] - leonardo.name=Arduino Leonardo - leonardo.upload.tool=avrdude - leonardo.upload.protocol=avr109 - leonardo.upload.maximum_size=28672 - leonardo.upload.speed=57600 - [.....] - -The **{upload.XXXX}** variables are used later in the avrdude upload recipe in platform.txt: - - [.....] - tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" - [.....] - -## Serial port - -The Arduino IDE auto-detects all available serial ports on the running system and lets the user choose one from the GUI. The selected port is available as a configuration property **{serial.port}**. - -## Upload using an external programmer - -**TODO...** -The platform.txt associated with the selected programmer will be used. - -## Burn Bootloader - -**TODO...** -The platform.txt associated with the selected board will be used. - -# Custom board menus - -The Arduino IDE allows adding extra menu items under the Tools menu. With these sub-menus the user can select different configurations for a specific board (for example a board could be provided in two or more variants with different CPUs, or may have different crystal speed based on the board model, and so on...). - -Let's see an example of how a custom menu is implemented. -The board used in the example is the Arduino Duemilanove. This board was produced in two models, one with an ATmega168 CPU and another with an ATmega328P. \ -We are going then to define a custom menu "Processor" that allows the user to choose between the two -different microcontrollers. - -We must first define a set of **menu.MENU_ID=Text** properties. Text is what is displayed on the GUI for every custom menu we are going to create and must be declared at the beginning of the boards.txt file: - - menu.cpu=Processor - [.....] - -in this case we declare only one custom menu "Processor" which we refer using the "cpu" MENU_ID. \ -Now let's add, always in the boards.txt file, the default configuration (common to all processors) for the duemilanove board: - - menu.cpu=Processor - [.....] - duemilanove.name=Arduino Duemilanove - duemilanove.upload.tool=avrdude - duemilanove.upload.protocol=arduino - duemilanove.build.f_cpu=16000000L - duemilanove.build.board=AVR_DUEMILANOVE - duemilanove.build.core=arduino - duemilanove.build.variant=standard - [.....] - -Now let's define the options to show in the "Processor" menu: - - [.....] - duemilanove.menu.cpu.atmega328=ATmega328P - [.....] - duemilanove.menu.cpu.atmega168=ATmega168 - [.....] - -We have defined two options: "ATmega328P" and "ATmega168". \ -Note that the property keys must follow the format **BOARD_ID.menu.MENU_ID.OPTION_ID=Text**. \ -Finally, the specific configuration for every option: - - [.....] - ## Arduino Duemilanove w/ ATmega328P - duemilanove.menu.cpu.atmega328=ATmega328P - duemilanove.menu.cpu.atmega328.upload.maximum_size=30720 - duemilanove.menu.cpu.atmega328.upload.speed=57600 - duemilanove.menu.cpu.atmega328.build.mcu=atmega328p - - ## Arduino Duemilanove w/ ATmega168 - duemilanove.menu.cpu.atmega168=ATmega168 - duemilanove.menu.cpu.atmega168.upload.maximum_size=14336 - duemilanove.menu.cpu.atmega168.upload.speed=19200 - duemilanove.menu.cpu.atmega168.build.mcu=atmega168 - [.....] - -Note that when the user selects an option, all the "sub properties" of that option are copied in the global configuration. For example when the user selects "ATmega168" from the "Processor" menu the Arduino IDE makes the configuration under atmega168 available globally: - - duemilanove.menu.cpu.atmega168.upload.maximum_size => upload.maximum_size - duemilanove.menu.cpu.atmega168.upload.speed => upload.speed - duemilanove.menu.cpu.atmega168.build.mcu => build.mcu - -There is no limit to the number of custom menus that can be defined. - -**TODO: add an example with more than one submenu** - -# Referencing another core, variant or tool - -Inside the boards.txt we can define a board that uses a core provided by another vendor/mantainer using the syntax **VENDOR_ID:CORE_ID**. For example, if we want to define a board that uses the "arduino" core from the "arduino" vendor we should write: - - [....] - myboard.name=My Wonderful Arduino Compatible board - myboard.build.core=arduino:arduino - [....] - -Note that we don't need to specify any architecture since the same architecture of "myboard" is used, so we just say "arduino:arduino" instead of "arduino:avr:arduino". - -The platform.txt settings are inherited from the referenced platform, thus there is no need to provide a platform.txt unless there are some specific properties that need to be overridden. - -The libraries from the referenced platform are used, thus there is no need to provide a libraries. If libraries are provided the list of available libraries are the sum of the 2 libraries where the referencing platform has priority over the referenced platform. - -In the same way we can use variants and tools defined on another platform: - - [....] - myboard.build.variant=arduino:standard - myboard.upload.tool=arduino:avrdude - myboard.bootloader.tool=arduino:avrdude - [....] - -Using this syntax allows us to reduce the minimum set of files needed to define a new "hardware" to just the boards.txt file. - - -# boards.local.txt - -Introduced in Arduino IDE 1.6.6. This file can be used to override properties defined in boards.txt or define new properties without modifying boards.txt. - - -# keywords.txt - -As of Arduino IDE 1.6.6, per-platform keywords can be defined by adding a keywords.txt file to the platform's architecture folder. These keywords are only highlighted when one of the boards of that platform are selected. This file follows the [same format](https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywords) as the keywords.txt used in libraries. Each keyword must be separated from the keyword identifier by a tab. - diff --git a/arduino/hardware/README.md b/arduino/hardware/README.md deleted file mode 100644 index b7e01ad..0000000 --- a/arduino/hardware/README.md +++ /dev/null @@ -1,3 +0,0 @@ -https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification -https://www.microchip.com/webdoc/AVRLibcReferenceManual/indexpage.html - diff --git a/arduino/hardware/ace/avr/boards.txt b/arduino/hardware/ace/avr/boards.txt deleted file mode 100644 index fe58bb9..0000000 --- a/arduino/hardware/ace/avr/boards.txt +++ /dev/null @@ -1,37 +0,0 @@ -# See: http://code.google.com/p/arduino/wiki/Platforms - -menu.cpu=Processor - -############################################################## - -uno.name=Ace Arduino Uno - -uno.vid.0=0x2341 -uno.pid.0=0x0043 -uno.vid.1=0x2341 -uno.pid.1=0x0001 -uno.vid.2=0x2A03 -uno.pid.2=0x0043 -uno.vid.3=0x2341 -uno.pid.3=0x0243 - -uno.upload.tool=avrdude -uno.upload.protocol=arduino -uno.upload.maximum_size=32256 -uno.upload.maximum_data_size=2048 -uno.upload.speed=115200 - -uno.bootloader.tool=avrdude -uno.bootloader.low_fuses=0xFF -uno.bootloader.high_fuses=0xDE -uno.bootloader.extended_fuses=0xFD -uno.bootloader.unlock_bits=0x3F -uno.bootloader.lock_bits=0x0F -uno.bootloader.file=optiboot_atmega328.hex - -uno.build.mcu=atmega328p -uno.build.f_cpu=16000000L -# The uno.build.board property is used to set a compile-time variable ARDUINO_{build.board} to allow use of conditional code between #ifdefs -uno.build.board=ACE_AVR -uno.build.core=avr -uno.build.variant=avr diff --git a/arduino/hardware/ace/avr/bootloaders/optiboot_atmega328.hex b/arduino/hardware/ace/avr/bootloaders/optiboot_atmega328.hex deleted file mode 100644 index a219f08..0000000 --- a/arduino/hardware/ace/avr/bootloaders/optiboot_atmega328.hex +++ /dev/null @@ -1,35 +0,0 @@ -:107E0000112484B714BE81FFF0D085E080938100F7 -:107E100082E08093C00088E18093C10086E0809377 -:107E2000C20080E18093C4008EE0C9D0259A86E02C -:107E300020E33CEF91E0309385002093840096BBD3 -:107E4000B09BFECF1D9AA8958150A9F7CC24DD24C4 -:107E500088248394B5E0AB2EA1E19A2EF3E0BF2EE7 -:107E6000A2D0813461F49FD0082FAFD0023811F036 -:107E7000013811F484E001C083E08DD089C08234E0 -:107E800011F484E103C0853419F485E0A6D080C0E4 -:107E9000853579F488D0E82EFF2485D0082F10E0AE -:107EA000102F00270E291F29000F111F8ED06801E7 -:107EB0006FC0863521F484E090D080E0DECF843638 -:107EC00009F040C070D06FD0082F6DD080E0C81688 -:107ED00080E7D80618F4F601B7BEE895C0E0D1E017 -:107EE00062D089930C17E1F7F0E0CF16F0E7DF06D8 -:107EF00018F0F601B7BEE89568D007B600FCFDCFD4 -:107F0000A601A0E0B1E02C9130E011968C91119780 -:107F100090E0982F8827822B932B1296FA010C0160 -:107F200087BEE89511244E5F5F4FF1E0A038BF0790 -:107F300051F7F601A7BEE89507B600FCFDCF97BE46 -:107F4000E89526C08437B1F42ED02DD0F82E2BD052 -:107F50003CD0F601EF2C8F010F5F1F4F84911BD097 -:107F6000EA94F801C1F70894C11CD11CFA94CF0C13 -:107F7000D11C0EC0853739F428D08EE10CD085E9AC -:107F80000AD08FE07ACF813511F488E018D01DD067 -:107F900080E101D065CF982F8091C00085FFFCCF94 -:107FA0009093C60008958091C00087FFFCCF809118 -:107FB000C00084FD01C0A8958091C6000895E0E648 -:107FC000F0E098E1908380830895EDDF803219F02E -:107FD00088E0F5DFFFCF84E1DECF1F93182FE3DFCA -:107FE0001150E9F7F2DF1F91089580E0E8DFEE27F6 -:047FF000FF270994CA -:027FFE00040479 -:0400000300007E007B -:00000001FF diff --git a/arduino/hardware/ace/avr/cores/avr/AceAvr.h b/arduino/hardware/ace/avr/cores/avr/AceAvr.h deleted file mode 100644 index 5bae26b..0000000 --- a/arduino/hardware/ace/avr/cores/avr/AceAvr.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: AceAvr.h - * Author: Zhao Yanbai - * 2018-06-14 20:28:08 Thursday CST - * Description: none - * ------------------------------------------------------------------------ - */ - -#pragma once - -#include -#include -#include - -#include -#include - -#define LOW 0 -#define HIGH 1 - -#define INPUT 0 -#define OUTPUT 1 -#define INPUT_PULLUP 2 - -void delay(unsigned long ms); -void acevest(); - -// ATmega328P -#define __SFR_OFFSET 0x20 -#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr)) -#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET) -#define DDRB _SFR_IO8(0x04) -#define PORTB _SFR_IO8(0x05) -#define DDRC _SFR_IO8(0x07) -#define PORTC _SFR_IO8(0x08) -#define DDRD _SFR_IO8(0x0A) -#define PORTD _SFR_IO8(0x0B) -#define SREG _SFR_IO8(0x3F) - -// F_CPU 定义在命令行中 -#ifndef F_CPU -#error "did not define F_CPU" -#endif -#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) -#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) -#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) -#define FRACT_MAX (1000 >> 3) - - -#define cli() __asm__ __volatile__ ("cli" ::: "memory") -#define sei() __asm__ __volatile__ ("sei" ::: "memory") -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) - - -#ifndef cbi -#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) -#endif -#ifndef sbi -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) -#endif - -const uint8_t PA = 1; -const uint8_t PB = 2; -const uint8_t PC = 3; -const uint8_t PD = 4; - - -uint8_t get_digital_pin_port(uint8_t pin); -uint8_t get_digital_pin_bit_mask(uint8_t pin); -volatile uint8_t* get_digital_pin_port_mode_register(uint8_t pin); -volatile uint8_t* get_digital_pin_port_output_register(uint8_t pin); - - -void set_digital_pin_mode(uint8_t pin, uint8_t mode); -void digital_write(uint8_t pin, uint8_t val); -void yield(void); - -unsigned long millis(); - - -typedef bool boolean; -typedef uint8_t byte; diff --git a/arduino/hardware/ace/avr/cores/avr/Arduino.h b/arduino/hardware/ace/avr/cores/avr/Arduino.h deleted file mode 100644 index b0774e2..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Arduino.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: Arduino.h - * Author: Zhao Yanbai - * 2018-06-14 20:01:07 Thursday CST - * Description: none - * ------------------------------------------------------------------------ - */ - -#pragma once diff --git a/arduino/hardware/ace/avr/cores/avr/HardwareSerial.cpp b/arduino/hardware/ace/avr/cores/avr/HardwareSerial.cpp deleted file mode 100644 index b63259a..0000000 --- a/arduino/hardware/ace/avr/cores/avr/HardwareSerial.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* - HardwareSerial.cpp - Hardware serial library for Wiring - Copyright (c) 2006 Nicholas Zambetti. 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 - - Modified 23 November 2006 by David A. Mellis - Modified 28 September 2010 by Mark Sproul - Modified 14 August 2012 by Alarus - Modified 3 December 2013 by Matthijs Kooijman -*/ - -#include -#include -#include -#include -#include "AceAvr.h" - -#include "HardwareSerial.h" -#include "HardwareSerial_private.h" - -// this next line disables the entire HardwareSerial.cpp, -// this is so I can support Attiny series and any other chip without a uart -#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3) - -// SerialEvent functions are weak, so when the user doesn't define them, -// the linker just sets their address to 0 (which is checked below). -// The Serialx_available is just a wrapper around Serialx.available(), -// but we can refer to it weakly so we don't pull in the entire -// HardwareSerial instance if the user doesn't also refer to it. -#if defined(HAVE_HWSERIAL0) - void serialEvent() __attribute__((weak)); - bool Serial0_available() __attribute__((weak)); -#endif - -#if defined(HAVE_HWSERIAL1) - void serialEvent1() __attribute__((weak)); - bool Serial1_available() __attribute__((weak)); -#endif - -#if defined(HAVE_HWSERIAL2) - void serialEvent2() __attribute__((weak)); - bool Serial2_available() __attribute__((weak)); -#endif - -#if defined(HAVE_HWSERIAL3) - void serialEvent3() __attribute__((weak)); - bool Serial3_available() __attribute__((weak)); -#endif - -void serialEventRun(void) -{ -#if defined(HAVE_HWSERIAL0) - if (Serial0_available && serialEvent && Serial0_available()) serialEvent(); -#endif -#if defined(HAVE_HWSERIAL1) - if (Serial1_available && serialEvent1 && Serial1_available()) serialEvent1(); -#endif -#if defined(HAVE_HWSERIAL2) - if (Serial2_available && serialEvent2 && Serial2_available()) serialEvent2(); -#endif -#if defined(HAVE_HWSERIAL3) - if (Serial3_available && serialEvent3 && Serial3_available()) serialEvent3(); -#endif -} - -// Actual interrupt handlers ////////////////////////////////////////////////////////////// - -void HardwareSerial::_tx_udr_empty_irq(void) -{ - // If interrupts are enabled, there must be more data in the output - // buffer. Send the next byte - unsigned char c = _tx_buffer[_tx_buffer_tail]; - _tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_TX_BUFFER_SIZE; - - *_udr = c; - - // clear the TXC bit -- "can be cleared by writing a one to its bit - // location". This makes sure flush() won't return until the bytes - // actually got written - sbi(*_ucsra, TXC0); - - if (_tx_buffer_head == _tx_buffer_tail) { - // Buffer empty, so disable interrupts - cbi(*_ucsrb, UDRIE0); - } -} - -// Public Methods ////////////////////////////////////////////////////////////// - -void HardwareSerial::begin(unsigned long baud, byte config) -{ - // Try u2x mode first - uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2; - *_ucsra = 1 << U2X0; - - // hardcoded exception for 57600 for compatibility with the bootloader - // shipped with the Duemilanove and previous boards and the firmware - // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot - // be > 4095, so switch back to non-u2x mode if the baud rate is too - // low. - if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095)) - { - *_ucsra = 0; - baud_setting = (F_CPU / 8 / baud - 1) / 2; - } - - // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register) - *_ubrrh = baud_setting >> 8; - *_ubrrl = baud_setting; - - _written = false; - - //set the data bits, parity, and stop bits -#if defined(__AVR_ATmega8__) - config |= 0x80; // select UCSRC register (shared with UBRRH) -#endif - *_ucsrc = config; - - sbi(*_ucsrb, RXEN0); - sbi(*_ucsrb, TXEN0); - sbi(*_ucsrb, RXCIE0); - cbi(*_ucsrb, UDRIE0); -} - -void HardwareSerial::end() -{ - // wait for transmission of outgoing data - flush(); - - cbi(*_ucsrb, RXEN0); - cbi(*_ucsrb, TXEN0); - cbi(*_ucsrb, RXCIE0); - cbi(*_ucsrb, UDRIE0); - - // clear any received data - _rx_buffer_head = _rx_buffer_tail; -} - -int HardwareSerial::available(void) -{ - return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE; -} - -int HardwareSerial::peek(void) -{ - if (_rx_buffer_head == _rx_buffer_tail) { - return -1; - } else { - return _rx_buffer[_rx_buffer_tail]; - } -} - -int HardwareSerial::read(void) -{ - // if the head isn't ahead of the tail, we don't have any characters - if (_rx_buffer_head == _rx_buffer_tail) { - return -1; - } else { - unsigned char c = _rx_buffer[_rx_buffer_tail]; - _rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE; - return c; - } -} - -int HardwareSerial::availableForWrite(void) -{ -#if (SERIAL_TX_BUFFER_SIZE>256) - uint8_t oldSREG = SREG; - cli(); -#endif - tx_buffer_index_t head = _tx_buffer_head; - tx_buffer_index_t tail = _tx_buffer_tail; -#if (SERIAL_TX_BUFFER_SIZE>256) - SREG = oldSREG; -#endif - if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail; - return tail - head - 1; -} - -void HardwareSerial::flush() -{ - // If we have never written a byte, no need to flush. This special - // case is needed since there is no way to force the TXC (transmit - // complete) bit to 1 during initialization - if (!_written) - return; - - while (bit_is_set(*_ucsrb, UDRIE0) || bit_is_clear(*_ucsra, TXC0)) { - if (bit_is_clear(SREG, SREG_I) && bit_is_set(*_ucsrb, UDRIE0)) - // Interrupts are globally disabled, but the DR empty - // interrupt should be enabled, so poll the DR empty flag to - // prevent deadlock - if (bit_is_set(*_ucsra, UDRE0)) - _tx_udr_empty_irq(); - } - // If we get here, nothing is queued anymore (DRIE is disabled) and - // the hardware finished tranmission (TXC is set). -} - -size_t HardwareSerial::write(uint8_t c) -{ - _written = true; - // If the buffer and the data register is empty, just write the byte - // to the data register and be done. This shortcut helps - // significantly improve the effective datarate at high (> - // 500kbit/s) bitrates, where interrupt overhead becomes a slowdown. - if (_tx_buffer_head == _tx_buffer_tail && bit_is_set(*_ucsra, UDRE0)) { - *_udr = c; - sbi(*_ucsra, TXC0); - return 1; - } - tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE; - - // If the output buffer is full, there's nothing for it other than to - // wait for the interrupt handler to empty it a bit - while (i == _tx_buffer_tail) { - if (bit_is_clear(SREG, SREG_I)) { - // Interrupts are disabled, so we'll have to poll the data - // register empty flag ourselves. If it is set, pretend an - // interrupt has happened and call the handler to free up - // space for us. - if(bit_is_set(*_ucsra, UDRE0)) - _tx_udr_empty_irq(); - } else { - // nop, the interrupt handler will free up space for us - } - } - - _tx_buffer[_tx_buffer_head] = c; - _tx_buffer_head = i; - - sbi(*_ucsrb, UDRIE0); - - return 1; -} - -#endif // whole file diff --git a/arduino/hardware/ace/avr/cores/avr/HardwareSerial.h b/arduino/hardware/ace/avr/cores/avr/HardwareSerial.h deleted file mode 100644 index e6b8ef5..0000000 --- a/arduino/hardware/ace/avr/cores/avr/HardwareSerial.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - HardwareSerial.h - Hardware serial library for Wiring - Copyright (c) 2006 Nicholas Zambetti. 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 - - Modified 28 September 2010 by Mark Sproul - Modified 14 August 2012 by Alarus - Modified 3 December 2013 by Matthijs Kooijman -*/ - -#ifndef HardwareSerial_h -#define HardwareSerial_h - -#include - -#include "Stream.h" - -// Define constants and variables for buffering incoming serial data. We're -// using a ring buffer (I think), in which head is the index of the location -// to which to write the next incoming character and tail is the index of the -// location from which to read. -// NOTE: a "power of 2" buffer size is reccomended to dramatically -// optimize all the modulo operations for ring buffers. -// WARNING: When buffer sizes are increased to > 256, the buffer index -// variables are automatically increased in size, but the extra -// atomicity guards needed for that are not implemented. This will -// often work, but occasionally a race condition can occur that makes -// Serial behave erratically. See https://github.com/arduino/Arduino/issues/2405 -#if !defined(SERIAL_TX_BUFFER_SIZE) -#if ((RAMEND - RAMSTART) < 1023) -#define SERIAL_TX_BUFFER_SIZE 16 -#else -#define SERIAL_TX_BUFFER_SIZE 64 -#endif -#endif -#if !defined(SERIAL_RX_BUFFER_SIZE) -#if ((RAMEND - RAMSTART) < 1023) -#define SERIAL_RX_BUFFER_SIZE 16 -#else -#define SERIAL_RX_BUFFER_SIZE 64 -#endif -#endif -#if (SERIAL_TX_BUFFER_SIZE>256) -typedef uint16_t tx_buffer_index_t; -#else -typedef uint8_t tx_buffer_index_t; -#endif -#if (SERIAL_RX_BUFFER_SIZE>256) -typedef uint16_t rx_buffer_index_t; -#else -typedef uint8_t rx_buffer_index_t; -#endif - -// Define config for Serial.begin(baud, config); -#define SERIAL_5N1 0x00 -#define SERIAL_6N1 0x02 -#define SERIAL_7N1 0x04 -#define SERIAL_8N1 0x06 -#define SERIAL_5N2 0x08 -#define SERIAL_6N2 0x0A -#define SERIAL_7N2 0x0C -#define SERIAL_8N2 0x0E -#define SERIAL_5E1 0x20 -#define SERIAL_6E1 0x22 -#define SERIAL_7E1 0x24 -#define SERIAL_8E1 0x26 -#define SERIAL_5E2 0x28 -#define SERIAL_6E2 0x2A -#define SERIAL_7E2 0x2C -#define SERIAL_8E2 0x2E -#define SERIAL_5O1 0x30 -#define SERIAL_6O1 0x32 -#define SERIAL_7O1 0x34 -#define SERIAL_8O1 0x36 -#define SERIAL_5O2 0x38 -#define SERIAL_6O2 0x3A -#define SERIAL_7O2 0x3C -#define SERIAL_8O2 0x3E - -class HardwareSerial : public Stream -{ - protected: - volatile uint8_t * const _ubrrh; - volatile uint8_t * const _ubrrl; - volatile uint8_t * const _ucsra; - volatile uint8_t * const _ucsrb; - volatile uint8_t * const _ucsrc; - volatile uint8_t * const _udr; - // Has any byte been written to the UART since begin() - bool _written; - - volatile rx_buffer_index_t _rx_buffer_head; - volatile rx_buffer_index_t _rx_buffer_tail; - volatile tx_buffer_index_t _tx_buffer_head; - volatile tx_buffer_index_t _tx_buffer_tail; - - // Don't put any members after these buffers, since only the first - // 32 bytes of this struct can be accessed quickly using the ldd - // instruction. - unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE]; - unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE]; - - public: - inline HardwareSerial( - volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, - volatile uint8_t *ucsra, volatile uint8_t *ucsrb, - volatile uint8_t *ucsrc, volatile uint8_t *udr); - void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } - void begin(unsigned long, uint8_t); - void end(); - virtual int available(void); - virtual int peek(void); - virtual int read(void); - virtual int availableForWrite(void); - virtual void flush(void); - virtual size_t write(uint8_t); - inline size_t write(unsigned long n) { return write((uint8_t)n); } - inline size_t write(long n) { return write((uint8_t)n); } - inline size_t write(unsigned int n) { return write((uint8_t)n); } - inline size_t write(int n) { return write((uint8_t)n); } - using Print::write; // pull in write(str) and write(buf, size) from Print - operator bool() { return true; } - - // Interrupt handlers - Not intended to be called externally - inline void _rx_complete_irq(void); - void _tx_udr_empty_irq(void); -}; - -#if defined(UBRRH) || defined(UBRR0H) - extern HardwareSerial Serial; - #define HAVE_HWSERIAL0 -#endif - -extern void serialEventRun(void) __attribute__((weak)); - -#endif diff --git a/arduino/hardware/ace/avr/cores/avr/HardwareSerial0.cpp b/arduino/hardware/ace/avr/cores/avr/HardwareSerial0.cpp deleted file mode 100644 index 03b163d..0000000 --- a/arduino/hardware/ace/avr/cores/avr/HardwareSerial0.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - HardwareSerial0.cpp - Hardware serial library for Wiring - Copyright (c) 2006 Nicholas Zambetti. 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 - - Modified 23 November 2006 by David A. Mellis - Modified 28 September 2010 by Mark Sproul - Modified 14 August 2012 by Alarus - Modified 3 December 2013 by Matthijs Kooijman -*/ - -#include "AceAvr.h" -#include "HardwareSerial.h" -#include "HardwareSerial_private.h" - -// Each HardwareSerial is defined in its own file, sine 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 -// HardwareSerial instance in as well. Putting each instance in its own -// file prevents the linker from pulling in any unused instances in the -// first place. - -#if defined(HAVE_HWSERIAL0) - -#if defined(USART_RX_vect) - ISR(USART_RX_vect) -#elif defined(USART0_RX_vect) - ISR(USART0_RX_vect) -#elif defined(USART_RXC_vect) - ISR(USART_RXC_vect) // ATmega8 -#else - #error "Don't know what the Data Received vector is called for Serial" -#endif - { - Serial._rx_complete_irq(); - } - -#if defined(UART0_UDRE_vect) -ISR(UART0_UDRE_vect) -#elif defined(UART_UDRE_vect) -ISR(UART_UDRE_vect) -#elif defined(USART0_UDRE_vect) -ISR(USART0_UDRE_vect) -#elif defined(USART_UDRE_vect) -ISR(USART_UDRE_vect) -#else - #error "Don't know what the Data Register Empty vector is called for Serial" -#endif -{ - Serial._tx_udr_empty_irq(); -} - -#if defined(UBRRH) && defined(UBRRL) - HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR); -#else - HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0); -#endif - -// Function that can be weakly referenced by serialEventRun to prevent -// pulling in this file if it's not otherwise used. -bool Serial0_available() { - return Serial.available(); -} - -#endif // HAVE_HWSERIAL0 diff --git a/arduino/hardware/ace/avr/cores/avr/HardwareSerial_private.h b/arduino/hardware/ace/avr/cores/avr/HardwareSerial_private.h deleted file mode 100644 index 259c3d1..0000000 --- a/arduino/hardware/ace/avr/cores/avr/HardwareSerial_private.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - HardwareSerial_private.h - Hardware serial library for Wiring - Copyright (c) 2006 Nicholas Zambetti. 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 - - Modified 23 November 2006 by David A. Mellis - Modified 28 September 2010 by Mark Sproul - Modified 14 August 2012 by Alarus -*/ - -#include "AceAvr.h" - -// this next line disables the entire HardwareSerial.cpp, -// this is so I can support Attiny series and any other chip without a uart -#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3) - -// Ensure that the various bit positions we use are available with a 0 -// postfix, so we can always use the values for UART0 for all UARTs. The -// alternative, passing the various values for each UART to the -// HardwareSerial constructor also works, but makes the code bigger and -// slower. -#if !defined(TXC0) -#if defined(TXC) -// Some chips like ATmega8 don't have UPE, only PE. The other bits are -// named as expected. -#if !defined(UPE) && defined(PE) -#define UPE PE -#endif -// On ATmega8, the uart and its bits are not numbered, so there is no TXC0 etc. -#define TXC0 TXC -#define RXEN0 RXEN -#define TXEN0 TXEN -#define RXCIE0 RXCIE -#define UDRIE0 UDRIE -#define U2X0 U2X -#define UPE0 UPE -#define UDRE0 UDRE -#elif defined(TXC1) -// Some devices have uart1 but no uart0 -#define TXC0 TXC1 -#define RXEN0 RXEN1 -#define TXEN0 TXEN1 -#define RXCIE0 RXCIE1 -#define UDRIE0 UDRIE1 -#define U2X0 U2X1 -#define UPE0 UPE1 -#define UDRE0 UDRE1 -#else -#error No UART found in HardwareSerial.cpp -#endif -#endif // !defined TXC0 - -// Check at compiletime that it is really ok to use the bit positions of -// UART0 for the other UARTs as well, in case these values ever get -// changed for future hardware. -#if defined(TXC1) && (TXC1 != TXC0 || RXEN1 != RXEN0 || RXCIE1 != RXCIE0 || \ - UDRIE1 != UDRIE0 || U2X1 != U2X0 || UPE1 != UPE0 || \ - UDRE1 != UDRE0) -#error "Not all bit positions for UART1 are the same as for UART0" -#endif -#if defined(TXC2) && (TXC2 != TXC0 || RXEN2 != RXEN0 || RXCIE2 != RXCIE0 || \ - UDRIE2 != UDRIE0 || U2X2 != U2X0 || UPE2 != UPE0 || \ - UDRE2 != UDRE0) -#error "Not all bit positions for UART2 are the same as for UART0" -#endif -#if defined(TXC3) && (TXC3 != TXC0 || RXEN3 != RXEN0 || RXCIE3 != RXCIE0 || \ - UDRIE3 != UDRIE0 || U3X3 != U3X0 || UPE3 != UPE0 || \ - UDRE3 != UDRE0) -#error "Not all bit positions for UART3 are the same as for UART0" -#endif - -// Constructors //////////////////////////////////////////////////////////////// - -HardwareSerial::HardwareSerial( - volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, - volatile uint8_t *ucsra, volatile uint8_t *ucsrb, - volatile uint8_t *ucsrc, volatile uint8_t *udr) : - _ubrrh(ubrrh), _ubrrl(ubrrl), - _ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc), - _udr(udr), - _rx_buffer_head(0), _rx_buffer_tail(0), - _tx_buffer_head(0), _tx_buffer_tail(0) -{ -} - -// Actual interrupt handlers ////////////////////////////////////////////////////////////// - -void HardwareSerial::_rx_complete_irq(void) -{ - if (bit_is_clear(*_ucsra, UPE0)) { - // No Parity error, read byte and store it in the buffer if there is - // room - unsigned char c = *_udr; - rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE; - - // if we should be storing the received character into the location - // just before the tail (meaning that the head would advance to the - // current location of the tail), we're about to overflow the buffer - // and so we don't write the character or advance the head. - if (i != _rx_buffer_tail) { - _rx_buffer[_rx_buffer_head] = c; - _rx_buffer_head = i; - } - } else { - // Parity error, read byte but discard it - *_udr; - }; -} - -#endif // whole file diff --git a/arduino/hardware/ace/avr/cores/avr/Print.cpp b/arduino/hardware/ace/avr/cores/avr/Print.cpp deleted file mode 100644 index b730016..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Print.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - Print.cpp - Base class that provides print() and println() - Copyright (c) 2008 David A. Mellis. 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 - - Modified 23 November 2006 by David A. Mellis - Modified 03 August 2015 by Chuck Todd - */ - -#include -#include -#include -#include -#include "AceAvr.h" - -#include "Print.h" - -// Public Methods ////////////////////////////////////////////////////////////// - -/* default implementation: may be overridden */ -size_t Print::write(const uint8_t *buffer, size_t size) -{ - size_t n = 0; - while (size--) { - if (write(*buffer++)) n++; - else break; - } - return n; -} - -size_t Print::print(const __FlashStringHelper *ifsh) -{ - PGM_P p = reinterpret_cast(ifsh); - size_t n = 0; - while (1) { - unsigned char c = pgm_read_byte(p++); - if (c == 0) break; - if (write(c)) n++; - else break; - } - return n; -} - -size_t Print::print(const String &s) -{ - return write(s.c_str(), s.length()); -} - -size_t Print::print(const char str[]) -{ - return write(str); -} - -size_t Print::print(char c) -{ - return write(c); -} - -size_t Print::print(unsigned char b, int base) -{ - return print((unsigned long) b, base); -} - -size_t Print::print(int n, int base) -{ - return print((long) n, base); -} - -size_t Print::print(unsigned int n, int base) -{ - return print((unsigned long) n, base); -} - -size_t Print::print(long n, int base) -{ - if (base == 0) { - return write(n); - } else if (base == 10) { - if (n < 0) { - int t = print('-'); - n = -n; - return printNumber(n, 10) + t; - } - return printNumber(n, 10); - } else { - return printNumber(n, base); - } -} - -size_t Print::print(unsigned long n, int base) -{ - if (base == 0) return write(n); - else return printNumber(n, base); -} - -size_t Print::print(double n, int digits) -{ - return printFloat(n, digits); -} - -size_t Print::println(const __FlashStringHelper *ifsh) -{ - size_t n = print(ifsh); - n += println(); - return n; -} - -size_t Print::print(const Printable& x) -{ - return x.printTo(*this); -} - -size_t Print::println(void) -{ - return write("\r\n"); -} - -size_t Print::println(const String &s) -{ - size_t n = print(s); - n += println(); - return n; -} - -size_t Print::println(const char c[]) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(char c) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(unsigned char b, int base) -{ - size_t n = print(b, base); - n += println(); - return n; -} - -size_t Print::println(int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(double num, int digits) -{ - size_t n = print(num, digits); - n += println(); - return n; -} - -size_t Print::println(const Printable& x) -{ - size_t n = print(x); - n += println(); - return n; -} - -// Private Methods ///////////////////////////////////////////////////////////// - -size_t Print::printNumber(unsigned long n, uint8_t base) -{ - char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. - char *str = &buf[sizeof(buf) - 1]; - - *str = '\0'; - - // prevent crash if called with base == 1 - if (base < 2) base = 10; - - do { - char c = n % base; - n /= base; - - *--str = c < 10 ? c + '0' : c + 'A' - 10; - } while(n); - - return write(str); -} - -size_t Print::printFloat(double number, uint8_t digits) -{ - size_t n = 0; - - if (isnan(number)) return print("nan"); - if (isinf(number)) return print("inf"); - if (number > 4294967040.0) return print ("ovf"); // constant determined empirically - if (number <-4294967040.0) return print ("ovf"); // constant determined empirically - - // Handle negative numbers - if (number < 0.0) - { - n += print('-'); - number = -number; - } - - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - for (uint8_t i=0; i 0) { - n += print('.'); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) - { - remainder *= 10.0; - unsigned int toPrint = (unsigned int)(remainder); - n += print(toPrint); - remainder -= toPrint; - } - - return n; -} diff --git a/arduino/hardware/ace/avr/cores/avr/Print.h b/arduino/hardware/ace/avr/cores/avr/Print.h deleted file mode 100644 index 058a2ab..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Print.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Print.h - Base class that provides print() and println() - Copyright (c) 2008 David A. Mellis. 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 -*/ - -#ifndef Print_h -#define Print_h - -#include -#include // for size_t - -#include "WString.h" -#include "Printable.h" - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar -#undef BIN -#endif -#define BIN 2 - -class Print -{ - private: - int write_error; - size_t printNumber(unsigned long, uint8_t); - size_t printFloat(double, uint8_t); - protected: - void setWriteError(int err = 1) { write_error = err; } - public: - Print() : write_error(0) {} - - int getWriteError() { return write_error; } - void clearWriteError() { setWriteError(0); } - - virtual size_t write(uint8_t) = 0; - size_t write(const char *str) { - if (str == NULL) return 0; - return write((const uint8_t *)str, strlen(str)); - } - virtual size_t write(const uint8_t *buffer, size_t size); - size_t write(const char *buffer, size_t size) { - return write((const uint8_t *)buffer, size); - } - - // default to zero, meaning "a single write may block" - // should be overriden by subclasses with buffering - virtual int availableForWrite() { return 0; } - - size_t print(const __FlashStringHelper *); - size_t print(const String &); - size_t print(const char[]); - size_t print(char); - size_t print(unsigned char, int = DEC); - size_t print(int, int = DEC); - size_t print(unsigned int, int = DEC); - size_t print(long, int = DEC); - size_t print(unsigned long, int = DEC); - size_t print(double, int = 2); - size_t print(const Printable&); - - size_t println(const __FlashStringHelper *); - size_t println(const String &s); - size_t println(const char[]); - size_t println(char); - size_t println(unsigned char, int = DEC); - size_t println(int, int = DEC); - size_t println(unsigned int, int = DEC); - size_t println(long, int = DEC); - size_t println(unsigned long, int = DEC); - size_t println(double, int = 2); - size_t println(const Printable&); - size_t println(void); - - virtual void flush() { /* Empty implementation for backward compatibility */ } -}; - -#endif diff --git a/arduino/hardware/ace/avr/cores/avr/Printable.h b/arduino/hardware/ace/avr/cores/avr/Printable.h deleted file mode 100644 index 2a1b2e9..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Printable.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Printable.h - Interface class that allows printing of complex types - Copyright (c) 2011 Adrian McEwen. 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 -*/ - -#ifndef Printable_h -#define Printable_h - -#include - -class Print; - -/** The Printable class provides a way for new classes to allow themselves to be printed. - By deriving from Printable and implementing the printTo method, it will then be possible - for users to print out instances of this class by passing them into the usual - Print::print and Print::println methods. -*/ - -class Printable -{ - public: - virtual size_t printTo(Print& p) const = 0; -}; - -#endif - diff --git a/arduino/hardware/ace/avr/cores/avr/Stream.cpp b/arduino/hardware/ace/avr/cores/avr/Stream.cpp deleted file mode 100644 index 52bd421..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Stream.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* - Stream.cpp - adds parsing methods to Stream class - Copyright (c) 2008 David A. Mellis. 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 - - Created July 2011 - parsing functions based on TextFinder library by Michael Margolis - - findMulti/findUntil routines written by Jim Leonard/Xuth - */ - -#include "AceAvr.h" -#include "Stream.h" - -#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait - -// protected method to read stream with timeout -int Stream::timedRead() -{ - int c; - _startMillis = millis(); - do { - c = read(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// protected method to peek stream with timeout -int Stream::timedPeek() -{ - int c; - _startMillis = millis(); - do { - c = peek(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// returns peek of the next digit in the stream or -1 if timeout -// discards non-numeric characters -int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal) -{ - int c; - while (1) { - c = timedPeek(); - - if( c < 0 || - c == '-' || - (c >= '0' && c <= '9') || - (detectDecimal && c == '.')) return c; - - switch( lookahead ){ - case SKIP_NONE: return -1; // Fail code. - case SKIP_WHITESPACE: - switch( c ){ - case ' ': - case '\t': - case '\r': - case '\n': break; - default: return -1; // Fail code. - } - case SKIP_ALL: - break; - } - read(); // discard non-numeric - } -} - -// Public Methods -////////////////////////////////////////////////////////////// - -void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait -{ - _timeout = timeout; -} - - // find returns true if the target string is found -bool Stream::find(char *target) -{ - return findUntil(target, strlen(target), NULL, 0); -} - -// reads data from the stream until the target string of given length is found -// returns true if target string is found, false if timed out -bool Stream::find(char *target, size_t length) -{ - return findUntil(target, length, NULL, 0); -} - -// as find but search ends if the terminator string is found -bool Stream::findUntil(char *target, char *terminator) -{ - return findUntil(target, strlen(target), terminator, strlen(terminator)); -} - -// reads data from the stream until the target string of the given length is found -// search terminated if the terminator string is found -// returns true if target string is found, false if terminated or timed out -bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) -{ - if (terminator == NULL) { - MultiTarget t[1] = {{target, targetLen, 0}}; - return findMulti(t, 1) == 0 ? true : false; - } else { - MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}}; - return findMulti(t, 2) == 0 ? true : false; - } -} - -// returns the first valid (long) integer value from the current position. -// lookahead determines how parseInt looks ahead in the stream. -// See LookaheadMode enumeration at the top of the file. -// Lookahead is terminated by the first character that is not a valid part of an integer. -// Once parsing commences, 'ignore' will be skipped in the stream. -long Stream::parseInt(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - long value = 0; - int c; - - c = peekNextDigit(lookahead, false); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if(c == ignore) - ; // ignore this character - else if(c == '-') - isNegative = true; - else if(c >= '0' && c <= '9') // is c a digit? - value = value * 10 + c - '0'; - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || c == ignore ); - - if(isNegative) - value = -value; - return value; -} - -// as parseInt but returns a floating point value -float Stream::parseFloat(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - bool isFraction = false; - long value = 0; - int c; - float fraction = 1.0; - - c = peekNextDigit(lookahead, true); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if(c == ignore) - ; // ignore - else if(c == '-') - isNegative = true; - else if (c == '.') - isFraction = true; - else if(c >= '0' && c <= '9') { // is c a digit? - value = value * 10 + c - '0'; - if(isFraction) - fraction *= 0.1; - } - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || c == ignore ); - - if(isNegative) - value = -value; - if(isFraction) - return value * fraction; - else - return value; -} - -// read characters from stream into buffer -// terminates if length characters have been read, or timeout (see setTimeout) -// returns the number of characters placed in the buffer -// the buffer is NOT null terminated. -// -size_t Stream::readBytes(char *buffer, size_t length) -{ - size_t count = 0; - while (count < length) { - int c = timedRead(); - if (c < 0) break; - *buffer++ = (char)c; - count++; - } - return count; -} - - -// as readBytes with terminator character -// terminates if length characters have been read, timeout, or if the terminator character detected -// returns the number of characters placed in the buffer (0 means no valid data found) - -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(); - if (c < 0 || c == terminator) break; - *buffer++ = (char)c; - index++; - } - return index; // return number of characters, not including null terminator -} - -String Stream::readString() -{ - String ret; - int c = timedRead(); - while (c >= 0) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -String Stream::readStringUntil(char terminator) -{ - String ret; - int c = timedRead(); - while (c >= 0 && c != terminator) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { - // any zero length target string automatically matches and would make - // a mess of the rest of the algorithm. - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - if (t->len <= 0) - return t - targets; - } - - while (1) { - int c = timedRead(); - if (c < 0) - return -1; - - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - // the simple case is if we match, deal with that first. - if (c == t->str[t->index]) { - if (++t->index == t->len) - return t - targets; - else - continue; - } - - // if not we need to walk back and see if we could have matched further - // down the stream (ie '1112' doesn't match the first position in '11112' - // but it will match the second position so we can't just reset the current - // index to 0 when we find a mismatch. - if (t->index == 0) - continue; - - int origIndex = t->index; - do { - --t->index; - // first check if current char works against the new current index - if (c != t->str[t->index]) - continue; - - // if it's the only char then we're good, nothing more to check - if (t->index == 0) { - t->index++; - break; - } - - // otherwise we need to check the rest of the found string - int diff = origIndex - t->index; - size_t i; - for (i = 0; i < t->index; ++i) { - if (t->str[i] != t->str[i + diff]) - break; - } - - // if we successfully got through the previous loop then our current - // index is good. - if (i == t->index) { - t->index++; - break; - } - - // otherwise we just try the next index - } while (t->index); - } - } - // unreachable - return -1; -} diff --git a/arduino/hardware/ace/avr/cores/avr/Stream.h b/arduino/hardware/ace/avr/cores/avr/Stream.h deleted file mode 100644 index 8e950c7..0000000 --- a/arduino/hardware/ace/avr/cores/avr/Stream.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - Stream.h - base class for character-based streams. - Copyright (c) 2010 David A. Mellis. 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 - - parsing functions based on TextFinder library by Michael Margolis -*/ - -#ifndef Stream_h -#define Stream_h - -#include -#include "Print.h" - -// compatability macros for testing -/* -#define getInt() parseInt() -#define getInt(ignore) parseInt(ignore) -#define getFloat() parseFloat() -#define getFloat(ignore) parseFloat(ignore) -#define getString( pre_string, post_string, buffer, length) -readBytesBetween( pre_string, terminator, buffer, length) -*/ - -// This enumeration provides the lookahead options for parseInt(), parseFloat() -// The rules set out here are used until either the first valid character is found -// or a time out occurs due to lack of input. -enum LookaheadMode{ - SKIP_ALL, // All invalid characters are ignored. - SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid. - SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped. -}; - -#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field - -class Stream : public Print -{ - protected: - unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read - unsigned long _startMillis; // used for timeout measurement - int timedRead(); // read stream with timeout - int timedPeek(); // peek stream with timeout - int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout - - public: - virtual int available() = 0; - virtual int read() = 0; - virtual int peek() = 0; - - Stream() {_timeout=1000;} - -// parsing methods - - void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second - unsigned long getTimeout(void) { return _timeout; } - - bool find(char *target); // reads data from the stream until the target string is found - bool find(uint8_t *target) { return find ((char *)target); } - // returns true if target string is found, false if timed out (see setTimeout) - - bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found - bool find(uint8_t *target, size_t length) { return find ((char *)target, length); } - // returns true if target string is found, false if timed out - - bool find(char target) { return find (&target, 1); } - - bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found - bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); } - - bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found - bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); } - - long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // returns the first valid (long) integer value from the current position. - // lookahead determines how parseInt looks ahead in the stream. - // See LookaheadMode enumeration at the top of the file. - // Lookahead is terminated by the first character that is not a valid part of an integer. - // Once parsing commences, 'ignore' will be skipped in the stream. - - float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // float version of parseInt - - size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer - size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); } - // terminates if length characters have been read or timeout (see setTimeout) - // returns the number of characters placed in the buffer (0 means no valid data found) - - size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character - size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); } - // terminates if length characters have been read, timeout, or if the terminator character detected - // returns the number of characters placed in the buffer (0 means no valid data found) - - // Arduino String functions to be added here - String readString(); - String readStringUntil(char terminator); - - protected: - long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); } - float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); } - // These overload exists for compatibility with any class that has derived - // Stream and used parseFloat/Int with a custom ignore character. To keep - // the public API simple, these overload remains protected. - - struct MultiTarget { - const char *str; // string you're searching for - size_t len; // length of string you're searching for - size_t index; // index used by the search routine. - }; - - // This allows you to search for an arbitrary number of strings. - // Returns index of the target that is found first or -1 if timeout occurs. - int findMulti(struct MultiTarget *targets, int tCount); -}; - -#undef NO_IGNORE_CHAR -#endif diff --git a/arduino/hardware/ace/avr/cores/avr/WString.cpp b/arduino/hardware/ace/avr/cores/avr/WString.cpp deleted file mode 100644 index f2572d6..0000000 --- a/arduino/hardware/ace/avr/cores/avr/WString.cpp +++ /dev/null @@ -1,750 +0,0 @@ -/* - WString.cpp - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All rights reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - 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 -*/ - -#include "WString.h" - -/*********************************************/ -/* Constructors */ -/*********************************************/ - -String::String(const char *cstr) -{ - init(); - if (cstr) copy(cstr, strlen(cstr)); -} - -String::String(const String &value) -{ - init(); - *this = value; -} - -String::String(const __FlashStringHelper *pstr) -{ - init(); - *this = pstr; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String::String(String &&rval) -{ - init(); - move(rval); -} -String::String(StringSumHelper &&rval) -{ - init(); - move(rval); -} -#endif - -String::String(char c) -{ - init(); - char buf[2]; - buf[0] = c; - buf[1] = 0; - *this = buf; -} - -String::String(unsigned char value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(int value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; -} - -String::String(unsigned int value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(long value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; -} - -String::String(unsigned long value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; -} - -String::String(float value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::String(double value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::~String() -{ - free(buffer); -} - -/*********************************************/ -/* Memory Management */ -/*********************************************/ - -inline void String::init(void) -{ - buffer = NULL; - capacity = 0; - len = 0; -} - -void String::invalidate(void) -{ - if (buffer) free(buffer); - buffer = NULL; - capacity = len = 0; -} - -unsigned char String::reserve(unsigned int size) -{ - if (buffer && capacity >= size) return 1; - if (changeBuffer(size)) { - if (len == 0) buffer[0] = 0; - return 1; - } - return 0; -} - -unsigned char String::changeBuffer(unsigned int maxStrLen) -{ - char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); - if (newbuffer) { - buffer = newbuffer; - capacity = maxStrLen; - return 1; - } - return 0; -} - -/*********************************************/ -/* Copy and Move */ -/*********************************************/ - -String & String::copy(const char *cstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy(buffer, cstr); - return *this; -} - -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -void String::move(String &rhs) -{ - if (buffer) { - if (rhs && capacity >= rhs.len) { - strcpy(buffer, rhs.buffer); - len = rhs.len; - rhs.len = 0; - return; - } else { - free(buffer); - } - } - buffer = rhs.buffer; - capacity = rhs.capacity; - len = rhs.len; - rhs.buffer = NULL; - rhs.capacity = 0; - rhs.len = 0; -} -#endif - -String & String::operator = (const String &rhs) -{ - if (this == &rhs) return *this; - - if (rhs.buffer) copy(rhs.buffer, rhs.len); - else invalidate(); - - return *this; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String & String::operator = (String &&rval) -{ - if (this != &rval) move(rval); - return *this; -} - -String & String::operator = (StringSumHelper &&rval) -{ - if (this != &rval) move(rval); - return *this; -} -#endif - -String & String::operator = (const char *cstr) -{ - if (cstr) copy(cstr, strlen(cstr)); - else invalidate(); - - return *this; -} - -String & String::operator = (const __FlashStringHelper *pstr) -{ - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - - return *this; -} - -/*********************************************/ -/* concat */ -/*********************************************/ - -unsigned char String::concat(const String &s) -{ - return concat(s.buffer, s.len); -} - -unsigned char String::concat(const char *cstr, unsigned int length) -{ - unsigned int newlen = len + length; - if (!cstr) return 0; - if (length == 0) return 1; - if (!reserve(newlen)) return 0; - strcpy(buffer + len, cstr); - len = newlen; - return 1; -} - -unsigned char String::concat(const char *cstr) -{ - if (!cstr) return 0; - return concat(cstr, strlen(cstr)); -} - -unsigned char String::concat(char c) -{ - char buf[2]; - buf[0] = c; - buf[1] = 0; - return concat(buf, 1); -} - -unsigned char String::concat(unsigned char num) -{ - char buf[1 + 3 * sizeof(unsigned char)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(int num) -{ - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned int num) -{ - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(long num) -{ - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned long num) -{ - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(float num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(double num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(const __FlashStringHelper * str) -{ - if (!str) return 0; - int length = strlen_P((const char *) str); - if (length == 0) return 1; - unsigned int newlen = len + length; - if (!reserve(newlen)) return 0; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return 1; -} - -/*********************************************/ -/* Concatenate */ -/*********************************************/ - -StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) -{ - StringSumHelper &a = const_cast(lhs); - if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, char c) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(c)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, float num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, double num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs)) a.invalidate(); - return a; -} - -/*********************************************/ -/* Comparison */ -/*********************************************/ - -int String::compareTo(const String &s) const -{ - if (!buffer || !s.buffer) { - if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, s.buffer); -} - -unsigned char String::equals(const String &s2) const -{ - return (len == s2.len && compareTo(s2) == 0); -} - -unsigned char String::equals(const char *cstr) const -{ - if (len == 0) return (cstr == NULL || *cstr == 0); - if (cstr == NULL) return buffer[0] == 0; - return strcmp(buffer, cstr) == 0; -} - -unsigned char String::operator<(const String &rhs) const -{ - return compareTo(rhs) < 0; -} - -unsigned char String::operator>(const String &rhs) const -{ - return compareTo(rhs) > 0; -} - -unsigned char String::operator<=(const String &rhs) const -{ - return compareTo(rhs) <= 0; -} - -unsigned char String::operator>=(const String &rhs) const -{ - return compareTo(rhs) >= 0; -} - -unsigned char String::equalsIgnoreCase( const String &s2 ) const -{ - if (this == &s2) return 1; - if (len != s2.len) return 0; - if (len == 0) return 1; - const char *p1 = buffer; - const char *p2 = s2.buffer; - while (*p1) { - if (tolower(*p1++) != tolower(*p2++)) return 0; - } - return 1; -} - -unsigned char String::startsWith( const String &s2 ) const -{ - if (len < s2.len) return 0; - return startsWith(s2, 0); -} - -unsigned char String::startsWith( const String &s2, unsigned int offset ) const -{ - if (offset > len - s2.len || !buffer || !s2.buffer) return 0; - return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; -} - -unsigned char String::endsWith( const String &s2 ) const -{ - if ( len < s2.len || !buffer || !s2.buffer) return 0; - return strcmp(&buffer[len - s2.len], s2.buffer) == 0; -} - -/*********************************************/ -/* Character Access */ -/*********************************************/ - -char String::charAt(unsigned int loc) const -{ - return operator[](loc); -} - -void String::setCharAt(unsigned int loc, char c) -{ - if (loc < len) buffer[loc] = c; -} - -char & String::operator[](unsigned int index) -{ - static char dummy_writable_char; - if (index >= len || !buffer) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return buffer[index]; -} - -char String::operator[]( unsigned int index ) const -{ - if (index >= len || !buffer) return 0; - return buffer[index]; -} - -void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const -{ - if (!bufsize || !buf) return; - if (index >= len) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if (n > len - index) n = len - index; - strncpy((char *)buf, buffer + index, n); - buf[n] = 0; -} - -/*********************************************/ -/* Search */ -/*********************************************/ - -int String::indexOf(char c) const -{ - return indexOf(c, 0); -} - -int String::indexOf( char ch, unsigned int fromIndex ) const -{ - if (fromIndex >= len) return -1; - const char* temp = strchr(buffer + fromIndex, ch); - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::indexOf(const String &s2) const -{ - return indexOf(s2, 0); -} - -int String::indexOf(const String &s2, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - const char *found = strstr(buffer + fromIndex, s2.buffer); - if (found == NULL) return -1; - return found - buffer; -} - -int String::lastIndexOf( char theChar ) const -{ - return lastIndexOf(theChar, len - 1); -} - -int String::lastIndexOf(char ch, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - char tempchar = buffer[fromIndex + 1]; - buffer[fromIndex + 1] = '\0'; - char* temp = strrchr( buffer, ch ); - buffer[fromIndex + 1] = tempchar; - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::lastIndexOf(const String &s2) const -{ - return lastIndexOf(s2, len - s2.len); -} - -int String::lastIndexOf(const String &s2, unsigned int fromIndex) const -{ - if (s2.len == 0 || len == 0 || s2.len > len) return -1; - if (fromIndex >= len) fromIndex = len - 1; - int found = -1; - for (char *p = buffer; p <= buffer + fromIndex; p++) { - p = strstr(p, s2.buffer); - if (!p) break; - if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; - } - return found; -} - -String String::substring(unsigned int left, unsigned int right) const -{ - if (left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if (left >= len) return out; - if (right > len) right = len; - char temp = buffer[right]; // save the replaced character - buffer[right] = '\0'; - out = buffer + left; // pointer arithmetic - buffer[right] = temp; //restore character - return out; -} - -/*********************************************/ -/* Modification */ -/*********************************************/ - -void String::replace(char find, char replace) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - if (*p == find) *p = replace; - } -} - -void String::replace(const String& find, const String& replace) -{ - if (len == 0 || find.len == 0) return; - int diff = replace.len - find.len; - char *readFrom = buffer; - char *foundAt; - if (diff == 0) { - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - memcpy(foundAt, replace.buffer, replace.len); - readFrom = foundAt + replace.len; - } - } else if (diff < 0) { - char *writeTo = buffer; - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - unsigned int n = foundAt - readFrom; - memcpy(writeTo, readFrom, n); - writeTo += n; - memcpy(writeTo, replace.buffer, replace.len); - writeTo += replace.len; - readFrom = foundAt + find.len; - len += diff; - } - strcpy(writeTo, readFrom); - } else { - unsigned int size = len; // compute size needed for result - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size += diff; - } - if (size == len) return; - if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); - len += diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } -} - -void String::remove(unsigned int index){ - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int)-1); -} - -void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - strncpy(writeTo, buffer + index + count,len - index); - buffer[len] = 0; -} - -void String::toLowerCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = tolower(*p); - } -} - -void String::toUpperCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = toupper(*p); - } -} - -void String::trim(void) -{ - if (!buffer || len == 0) return; - char *begin = buffer; - while (isspace(*begin)) begin++; - char *end = buffer + len - 1; - while (isspace(*end) && end >= begin) end--; - len = end + 1 - begin; - if (begin > buffer) memcpy(buffer, begin, len); - buffer[len] = 0; -} - -/*********************************************/ -/* Parsing / Conversion */ -/*********************************************/ - -long String::toInt(void) const -{ - if (buffer) return atol(buffer); - return 0; -} - -float String::toFloat(void) const -{ - return float(toDouble()); -} - -double String::toDouble(void) const -{ - if (buffer) return atof(buffer); - return 0; -} diff --git a/arduino/hardware/ace/avr/cores/avr/WString.h b/arduino/hardware/ace/avr/cores/avr/WString.h deleted file mode 100644 index 77709c3..0000000 --- a/arduino/hardware/ace/avr/cores/avr/WString.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - WString.h - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All right reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - 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 -*/ - -#ifndef String_class_h -#define String_class_h -#ifdef __cplusplus - -#include -#include -#include -#include - -// When compiling programs with this class, the following gcc parameters -// dramatically increase performance and memory (RAM) efficiency, typically -// with little or no increase in code size. -// -felide-constructors -// -std=c++0x - -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - -// An inherited class for holding the result of a concatenation. These -// result objects are assumed to be writable by subsequent concatenations. -class StringSumHelper; - -// The string class -class String -{ - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const {} - -public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const String &str); - String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String(String &&rval); - String(StringSumHelper &&rval); - #endif - explicit String(char c); - explicit String(unsigned char, unsigned char base=10); - explicit String(int, unsigned char base=10); - explicit String(unsigned int, unsigned char base=10); - explicit String(long, unsigned char base=10); - explicit String(unsigned long, unsigned char base=10); - explicit String(float, unsigned char decimalPlaces=2); - explicit String(double, unsigned char decimalPlaces=2); - ~String(void); - - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - unsigned char reserve(unsigned int size); - inline unsigned int length(void) const {return len;} - - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator = (const String &rhs); - String & operator = (const char *cstr); - String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String & operator = (String &&rval); - String & operator = (StringSumHelper &&rval); - #endif - - // concatenate (works w/ built-in types) - - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. - unsigned char concat(const String &str); - unsigned char concat(const char *cstr); - unsigned char concat(char c); - unsigned char concat(unsigned char c); - unsigned char concat(int num); - unsigned char concat(unsigned int num); - unsigned char concat(long num); - unsigned char concat(unsigned long num); - unsigned char concat(float num); - unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); - - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator += (const String &rhs) {concat(rhs); return (*this);} - String & operator += (const char *cstr) {concat(cstr); return (*this);} - String & operator += (char c) {concat(c); return (*this);} - String & operator += (unsigned char num) {concat(num); return (*this);} - String & operator += (int num) {concat(num); return (*this);} - String & operator += (unsigned int num) {concat(num); return (*this);} - String & operator += (long num) {concat(num); return (*this);} - String & operator += (unsigned long num) {concat(num); return (*this);} - String & operator += (float num) {concat(num); return (*this);} - String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} - - friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); - - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } - int compareTo(const String &s) const; - unsigned char equals(const String &s) const; - unsigned char equals(const char *cstr) const; - unsigned char operator == (const String &rhs) const {return equals(rhs);} - unsigned char operator == (const char *cstr) const {return equals(cstr);} - unsigned char operator != (const String &rhs) const {return !equals(rhs);} - unsigned char operator != (const char *cstr) const {return !equals(cstr);} - unsigned char operator < (const String &rhs) const; - unsigned char operator > (const String &rhs) const; - unsigned char operator <= (const String &rhs) const; - unsigned char operator >= (const String &rhs) const; - unsigned char equalsIgnoreCase(const String &s) const; - unsigned char startsWith( const String &prefix) const; - unsigned char startsWith(const String &prefix, unsigned int offset) const; - unsigned char endsWith(const String &suffix) const; - - // character acccess - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [] (unsigned int index) const; - char& operator [] (unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - { getBytes((unsigned char *)buf, bufsize, index); } - const char* c_str() const { return buffer; } - char* begin() { return buffer; } - char* end() { return buffer + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } - - // search - int indexOf( char ch ) const; - int indexOf( char ch, unsigned int fromIndex ) const; - int indexOf( const String &str ) const; - int indexOf( const String &str, unsigned int fromIndex ) const; - int lastIndexOf( char ch ) const; - int lastIndexOf( char ch, unsigned int fromIndex ) const; - int lastIndexOf( const String &str ) const; - int lastIndexOf( const String &str, unsigned int fromIndex ) const; - String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; - String substring( unsigned int beginIndex, unsigned int endIndex ) const; - - // modification - void replace(char find, char replace); - void replace(const String& find, const String& replace); - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); - - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; - -protected: - char *buffer; // the actual char array - unsigned int capacity; // the array length minus one (for the '\0') - unsigned int len; // the String length (not counting the '\0') -protected: - void init(void); - void invalidate(void); - unsigned char changeBuffer(unsigned int maxStrLen); - unsigned char concat(const char *cstr, unsigned int length); - - // copy and move - String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - void move(String &rhs); - #endif -}; - -class StringSumHelper : public String -{ -public: - StringSumHelper(const String &s) : String(s) {} - StringSumHelper(const char *p) : String(p) {} - StringSumHelper(char c) : String(c) {} - StringSumHelper(unsigned char num) : String(num) {} - StringSumHelper(int num) : String(num) {} - StringSumHelper(unsigned int num) : String(num) {} - StringSumHelper(long num) : String(num) {} - StringSumHelper(unsigned long num) : String(num) {} - StringSumHelper(float num) : String(num) {} - StringSumHelper(double num) : String(num) {} -}; - -#endif // __cplusplus -#endif // String_class_h diff --git a/arduino/hardware/ace/avr/cores/avr/acevest.cpp b/arduino/hardware/ace/avr/cores/avr/acevest.cpp deleted file mode 100644 index c94bc1a..0000000 --- a/arduino/hardware/ace/avr/cores/avr/acevest.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: acevest.cpp - * Author: Zhao Yanbai - * 2018-06-14 20:27:23 Thursday CST - * Description: none - * ------------------------------------------------------------------------ - */ -void acevest() { - - -} diff --git a/arduino/hardware/ace/avr/cores/avr/app.cpp b/arduino/hardware/ace/avr/cores/avr/app.cpp deleted file mode 100644 index 0b517b9..0000000 --- a/arduino/hardware/ace/avr/cores/avr/app.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: app.cpp - * Author: Zhao Yanbai - * 2018-06-18 16:01:26 Monday CST - * Description: none - * ------------------------------------------------------------------------ - */ -#include - -uint8_t debug_task_stack[TASK_STACK_SIZE]; -void debug_task() { - while(1) { - Serial.println("debug task"); - task_delay(1000); - } -} - -uint8_t led_task_stack[TASK_STACK_SIZE]; -void led_task() { - uint8_t pin = 13; - set_digital_pin_mode(pin, OUTPUT); - while(1) { - digital_write(pin, HIGH); - task_delay(10); - digital_write(pin, LOW); - task_delay(10); - } -} - -uint8_t user_task1_stack[TASK_STACK_SIZE]; -void user_task1() { - int cnt = 0; - while(1) { - Serial.print("user task 1, cnt: "); - Serial.println(cnt++); - task_delay(100); - } -} - -#if 1 -uint8_t user_task2_stack[TASK_STACK_SIZE]; -void user_task2() { - int cnt = 0; - uint8_t pin = 14; - set_digital_pin_mode(pin, OUTPUT); - uint8_t state = LOW; - - while(1) { - state = state == LOW ? HIGH : LOW; - digital_write(pin, state); - Serial.print("user task 2, cnt: "); - Serial.println(cnt++); - task_delay(random() % 50); - } -} -#endif - - - -void app_main() { - Serial.begin(9600); - create_task(led_task, led_task_stack, 0); - create_task(user_task1, user_task1_stack, 1); - create_task(user_task2, user_task2_stack, 2); - create_task(debug_task, debug_task_stack, 3); -} - - diff --git a/arduino/hardware/ace/avr/cores/avr/avr.cpp b/arduino/hardware/ace/avr/cores/avr/avr.cpp deleted file mode 100644 index f61ed70..0000000 --- a/arduino/hardware/ace/avr/cores/avr/avr.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include - -// On the board, digital pins are also used -// for the analog output (software PWM). Analog input -// pins are a separate set. - -// ATMEL ATMEGA328P -// -// +-\/-+ -// PC6 1| |28 PC5 (AI 5) (D 19) -// (D 0) PD0 2| |27 PC4 (AI 4) (D 18) -// (D 1) PD1 3| |26 PC3 (AI 3) (D 17) -// (D 2) PD2 4| |25 PC2 (AI 2) (D 16) -// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) (D 15) -// (D 4) PD4 6| |23 PC0 (AI 0) (D 14) -// VCC 7| |22 GND -// GND 8| |21 AREF -// PB6 9| |20 AVCC -// PB7 10| |19 PB5 (D 13) -// PWM+ (D 5) PD5 11| |18 PB4 (D 12) -// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM -// (D 7) PD7 13| |16 PB2 (D 10) PWM -// (D 8) PB0 14| |15 PB1 (D 9) PWM -// +----+ -// -// (PWM+ indicates the additional PWM pins on the ATmega168.) - -uint8_t get_digital_pin_port(uint8_t pin) { - if(pin < 8) { - return PD; - } - - if(pin < 14) { - return PB; - } - - return PC; -} - -uint8_t get_digital_pin_bit_mask(uint8_t pin) { - uint8_t seg = 0; - - switch(get_digital_pin_port(pin)) { - case PB: - seg = 8; - break; - case PC: - seg = 14; - break; - case PD: - seg = 0; - break; - } - - return (1 << (pin - seg)); -} - -volatile uint8_t* get_digital_pin_port_mode_register(uint8_t pin) { - switch(get_digital_pin_port(pin)) { - case PB: - return &DDRB; - case PC: - return &DDRC; - case PD: - return &DDRD; - } - - return 0; -} - - -volatile uint8_t* get_digital_pin_port_output_register(uint8_t pin) { - switch(get_digital_pin_port(pin)) { - case PB: - return &PORTB; - case PC: - return &PORTC; - case PD: - return &PORTC; - } - - return 0; -} diff --git a/arduino/hardware/ace/avr/cores/avr/backup/code0 b/arduino/hardware/ace/avr/cores/avr/backup/code0 deleted file mode 100644 index 6dd2c25..0000000 --- a/arduino/hardware/ace/avr/cores/avr/backup/code0 +++ /dev/null @@ -1,187 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: main.cpp - * Author: Zhao Yanbai - * 2018-06-14 20:21:33 Thursday CST - * Description: none - * ------------------------------------------------------------------------ - */ -#include -#include -#include - -#define __SFR_OFFSET 0x20 -#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr)) -#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET) -#define SREG _SFR_IO8(0x3F) -#define DDRB _SFR_IO8(0x04) -#define PORTB _SFR_IO8(0x05) -#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) -#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) -#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) -#define FRACT_MAX (1000 >> 3) - -#define cli() __asm__ __volatile__ ("cli" ::: "memory") -#define sei() __asm__ __volatile__ ("sei" ::: "memory") -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) - - -#define __INTR_ATTRS used, externally_visible -#ifdef __cplusplus -# define ISR(vector, ...) \ - extern "C" void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \ - void vector (void) -#else -# define ISR(vector, ...) \ - void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \ - void vector (void) -#endif - -volatile unsigned long timer0_overflow_count = 0; -volatile unsigned long timer0_millis = 0; -static unsigned char timer0_fract = 0; - -ISR(TIMER0_OVF_vect) -{ - // copy these to local variables so they can be stored in registers - // (volatile variables must be read from memory on every access) - unsigned long m = timer0_millis; - unsigned char f = timer0_fract; - - m += MILLIS_INC; - f += FRACT_INC; - if (f >= FRACT_MAX) { - f -= FRACT_MAX; - m += 1; - } - - timer0_fract = f; - timer0_millis = m; - timer0_overflow_count++; -} - -static void __empty() { - // Empty -} -//void yield(void) __attribute__ ((weak, alias("__empty"))); -void yield(void) { } - -unsigned long micros() { - unsigned long m; - uint8_t oldSREG = SREG, t; - - cli(); - m = timer0_overflow_count; - - t = TCNT0; - if ((TIFR0 & _BV(TOV0)) && (t < 255)) { - m++; - } - SREG = oldSREG; - - return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); -} - -void delay(unsigned long ms) -{ - uint32_t start = micros(); - while (ms > 0) { - yield(); - while ( ms > 0 && (micros() - start) >= 1000) { - ms--; - start += 1000; - } - } -} - - - - - -void init() { - sei(); - - // on the ATmega168, timer 0 is also used for fast hardware pwm - // (using phase-correct PWM would mean that timer 0 overflowed half as often - // resulting in different millis() behavior on the ATmega8 and ATmega168) - sbi(TCCR0A, WGM01); - sbi(TCCR0A, WGM00); - - // set timer 0 prescale factor to 64 - sbi(TCCR0B, CS01); - sbi(TCCR0B, CS00); - - // enable timer 0 overflow interrupt - sbi(TIMSK0, TOIE0); - -#if 0 - // timers 1 and 2 are used for phase-correct hardware pwm - // this is better for motors as it ensures an even waveform - // note, however, that fast pwm mode can achieve a frequency of up - // 8 MHz (with a 16 MHz clock) at 50% duty cycle - TCCR1B = 0; - sbi(TCCR1B, CS11); -//#if F_CPU >= 8000000L - sbi(TCCR1B, CS10); -//#endif - // put timer 1 in 8-bit phase correct pwm mode - sbi(TCCR1A, WGM10); - - // set timer 2 prescale factor to 64 - sbi(TCCR2B, CS22); - // configure timer 2 for phase correct pwm (8-bit) - sbi(TCCR2A, WGM20); - -//#if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz - sbi(ADCSRA, ADPS2); - sbi(ADCSRA, ADPS1); - sbi(ADCSRA, ADPS0); -//#endif - sbi(ADCSRA, ADEN); - - // the bootloader connects pins 0 and 1 to the USART; disconnect them - // here so they can be used as normal digital i/o; they will be - // reconnected in Serial.begin() - UCSR0B = 0; -#endif -} - -int main() -{ - init(); - - uint8_t pin = 5; - uint8_t bit = 1< - - -#if 0 -volatile unsigned long timer0_overflow_count = 0; - -//extern "C" void TIMER0_OVF_vect() __attribute__ ((signal,used, externally_visible)); -//void TIMER0_OVF_vect() - -extern "C" void __vector_16() __attribute__ ((signal,used, externally_visible)); -void __vector_16() -{ - timer0_overflow_count++; -} - - - -int main() { -__asm__ __volatile__ ("sei" ::: "memory"); -__asm__ __volatile__ ("nop" ::: "memory"); -__asm__ __volatile__ ("nop" ::: "memory"); - uint8_t oldSREG = SREG; - oldSREG = 0xAA; - SREG = oldSREG; - uint16_t x = (uint16_t)(&DDRB); - x++; -__asm__ __volatile__ ("nop" ::: "memory"); -__asm__ __volatile__ ("nop" ::: "memory"); -__asm__ __volatile__ ("cli" ::: "memory"); - - return 0; -} -#else - -void init_timer0(); - -void init() { - sei(); - init_timer0(); -} - -int main() -{ - init(); - - //uint8_t pin = 13; - uint8_t bit = 1<<4; // pin 13是 B组的第5个 - volatile uint8_t *reg = ((volatile uint8_t *)((uint16_t)(&DDRB))); - volatile uint8_t *out = ((volatile uint8_t *)((uint16_t)(&PORTB))); - - // set pin output - uint8_t oldSREG = SREG; - cli(); - *reg |= bit; - SREG = oldSREG; - - const int d = 1000; - int n = 0; - - while(1) { - n++; - - oldSREG = SREG; - cli(); - /* HIGH */ /* LOW */ - n % 2 == 0 ? *out |= bit : *out &= ~bit; - SREG = oldSREG; - - delay(d); - } - - return 0; -} -#endif diff --git a/arduino/hardware/ace/avr/cores/avr/kernel.cpp b/arduino/hardware/ace/avr/cores/avr/kernel.cpp deleted file mode 100644 index eaa37d8..0000000 --- a/arduino/hardware/ace/avr/cores/avr/kernel.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: kernel.cpp - * Author: Zhao Yanbai - * 2018-06-17 16:42:56 Sunday CST - * Description: none - * ------------------------------------------------------------------------ - */ -#include -#include - -void delay(unsigned long ms); - -const uint8_t task_cnt = MAX_TASK_CNT + 1; -const uint8_t idle_task_priority = task_cnt - 1; -struct task *current_task = 0; -struct task tasks[task_cnt]; -uint32_t ticks = 0; -int8_t kernel_initialized = 0; - -#define IDLE_TASK (tasks+task_cnt-1) -#define LED_TASK (tasks+0); -#define DEBUG_TASK (tasks+1); - -void task_scheduler(); - -// idle_task 在没有进程READY的情况下都会调度运行 -// 所以task_delay不能在此进程生效 -uint8_t idle_task_stack[TASK_STACK_SIZE]; -uint32_t idle_cnt = 0; -void app_main(); -void idle_task() { - sei(); - kernel_initialized = 1; - app_main(); - uint8_t pin = 12; - set_digital_pin_mode(pin, OUTPUT); - uint8_t state = LOW; - while(1) { - idle_cnt++; - state = state == LOW ? HIGH : LOW; - digital_write(pin, state); - delay(1000); - } -} - - -void task_delay(uint16_t ticks) -{ - current_task->state = TASK_STATE_SLEEP; - current_task->delay_ticks = ticks; - task_scheduler(); -} - -void create_task(void (*handler)(), uint8_t *stack, uint8_t priority) -{ - if(priority == idle_task_priority && handler != idle_task) { - return; - } - - if(priority > task_cnt) { - return; - } - - struct task *t = tasks + priority; - t->handler = handler; - t->state = TASK_STATE_READY; - - t->stack = stack + TASK_STACK_SIZE - 3; - uint8_t *p = t->stack; - // 貌似atmega328p执行RET会弹出3个字节给到PC寄存器 - *(p+0) = (((uint32_t)handler) >> 16); - *(p+1) = (((uint32_t)handler) >> 8); - *(p+2) = (((uint32_t)handler) >> 0); - *(--(t->stack)) = 0x00; // SREG - *(--(t->stack)) = 0x00; // R0 - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; // R10 - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; // 20 - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; - *(--(t->stack)) = 0x00; // 30 - *(--(t->stack)) = 0x00; -} - -void task_switch(struct task *prev, struct task *next) { - if(prev == next) { - return; - } - - SAVE_CONTEXT; - - prev->stack = (uint8_t *) SP; - SP = ((uint16_t)next->stack); - current_task = next; - - RESTORE_CONTEXT; - __asm__ __volatile__("ret"); - -} - -void task_scheduler() { - struct task *next = IDLE_TASK; - for(uint8_t i=0; istate) { - next = t; - break; - } - } - - task_switch(current_task, next); -} - -void yield(void) -{ - if(kernel_initialized == 0) { - return ; - } - - task_scheduler(); -} - -extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal,used, externally_visible)); -void TIMER1_COMPA_vect() -{ - ticks++; - - for(uint8_t i=0; istate) { - continue; - } - - if(t->delay_ticks > 0) { - t->delay_ticks--; - } - - if(t->delay_ticks == 0) { - t->state = TASK_STATE_READY; - } - } - - task_scheduler(); -} - -void init_timer1() { - //set timer1 interrupt at 100Hz - TCCR1A = 0;// set entire TCCR1A register to 0 - TCCR1B = 0;// same for TCCR1B - TCNT1 = 0;//initialize counter value to 0 - // set compare match register for 100Hz increments - OCR1A = 155; // = (16*10^6) / (1024*100Hz) - 1 (must be <65536) - // turn on CTC mode - TCCR1B |= (1 << WGM12); - // Set CS10 and CS12 bits for 1024 prescaler - TCCR1B |= (1 << CS12) | (1 << CS10); - // enable timer compare interrupt - TIMSK1 |= (1 << OCIE1A); -} - -void init_tasks() { - cli(); - for(uint8_t i=0; ipid = i; - t->handler = 0; - t->stack = 0; - t->state = TASK_STATE_EMPTY; - t->delay_ticks = 0; - } - - create_task(idle_task, idle_task_stack, idle_task_priority); - current_task = IDLE_TASK; - IDLE_TASK->stack = idle_task_stack+TASK_STACK_SIZE - 3; - - SP = (uint16_t)(IDLE_TASK->stack); - asm("ret;"); -} - - diff --git a/arduino/hardware/ace/avr/cores/avr/kernel.h b/arduino/hardware/ace/avr/cores/avr/kernel.h deleted file mode 100644 index b3e72cf..0000000 --- a/arduino/hardware/ace/avr/cores/avr/kernel.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: kernel.h - * Author: Zhao Yanbai - * 2018-06-17 16:42:52 Sunday CST - * Description: none - * ------------------------------------------------------------------------ - */ - -#pragma once -#include - -#define MAX_TASK_CNT 8 -#define TASK_STACK_SIZE 256 - -#if MAX_TASK_CNT > 32 -#error "too much tasks" -#endif - -enum task_state { - TASK_STATE_EMPTY = 0, - TASK_STATE_READY = 1, - TASK_STATE_SLEEP = 2, -}; - -struct task { - uint8_t pid; - enum task_state state; - void (*handler)(); - uint8_t* stack; - uint16_t delay_ticks; -}; - -void init_tasks(); -void create_task(void (*handler)(), uint8_t *stack, uint8_t priority); -void task_switch(struct task *prev, struct task *next); -void task_delay(uint16_t ticks); -//void yield(void); - -#define SAVE_CONTEXT \ - __asm__ __volatile__( \ - "PUSH R31\n" \ - "PUSH R30\n" \ - "PUSH R29\n" \ - "PUSH R28\n" \ - "PUSH R27\n" \ - "PUSH R26\n" \ - "PUSH R25\n" \ - "PUSH R24\n" \ - "PUSH R23\n" \ - "PUSH R22\n" \ - "PUSH R21\n" \ - "PUSH R20\n" \ - "PUSH R19\n" \ - "PUSH R18\n" \ - "PUSH R17\n" \ - "PUSH R16\n" \ - "PUSH R15\n" \ - "PUSH R14\n" \ - "PUSH R13\n" \ - "PUSH R12\n" \ - "PUSH R11\n" \ - "PUSH R10\n" \ - "PUSH R09\n" \ - "PUSH R08\n" \ - "PUSH R07\n" \ - "PUSH R06\n" \ - "PUSH R05\n" \ - "PUSH R04\n" \ - "PUSH R03\n" \ - "PUSH R02\n" \ - "PUSH R01\n" \ - "PUSH R00\n" \ - "IN R00, __SREG__\n" \ - "PUSH R00\n" \ - ); - -#define RESTORE_CONTEXT \ - __asm__ __volatile__( \ - "POP R00\n" \ - "OUT __SREG__, R00\n" \ - "POP R00\n" \ - "POP R01\n" \ - "POP R02\n" \ - "POP R03\n" \ - "POP R04\n" \ - "POP R05\n" \ - "POP R06\n" \ - "POP R07\n" \ - "POP R08\n" \ - "POP R09\n" \ - "POP R10\n" \ - "POP R11\n" \ - "POP R12\n" \ - "POP R13\n" \ - "POP R14\n" \ - "POP R15\n" \ - "POP R16\n" \ - "POP R17\n" \ - "POP R18\n" \ - "POP R19\n" \ - "POP R20\n" \ - "POP R21\n" \ - "POP R22\n" \ - "POP R23\n" \ - "POP R24\n" \ - "POP R25\n" \ - "POP R26\n" \ - "POP R27\n" \ - "POP R28\n" \ - "POP R29\n" \ - "POP R30\n" \ - "POP R31\n" \ - "reti\n"\ - ); - diff --git a/arduino/hardware/ace/avr/cores/avr/lib.cpp b/arduino/hardware/ace/avr/cores/avr/lib.cpp deleted file mode 100644 index c2bd8dc..0000000 --- a/arduino/hardware/ace/avr/cores/avr/lib.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: lib.cpp - * Author: Zhao Yanbai - * 2018-06-17 15:27:28 Sunday CST - * Description: none - * ------------------------------------------------------------------------ - */ -#include - -void set_digital_pin_mode(uint8_t pin, uint8_t mode) { - uint8_t bit_mask = get_digital_pin_bit_mask(pin); - volatile uint8_t *mod_reg = get_digital_pin_port_mode_register(pin); - volatile uint8_t *out_reg = get_digital_pin_port_output_register(pin); - - if(0 == mod_reg || 0 == out_reg) return; - - uint8_t oldSREG = SREG; - cli(); - - switch(mode) { - case INPUT: - *mod_reg &= ~bit_mask; - *out_reg &= ~bit_mask; - break; - case INPUT_PULLUP: - *mod_reg &= ~bit_mask; - *out_reg |= ~bit_mask; - break; - case OUTPUT: - *mod_reg |= bit_mask; - break; - } - - SREG = oldSREG; -} - -void digital_write(uint8_t pin, uint8_t val) { - uint8_t bit_mask = get_digital_pin_bit_mask(pin); - volatile uint8_t *out_reg = get_digital_pin_port_output_register(pin); - - uint8_t oldSREG = SREG; - cli(); - val == LOW ? *out_reg &= ~bit_mask : *out_reg |= bit_mask; - SREG = oldSREG; -} diff --git a/arduino/hardware/ace/avr/cores/avr/main.cpp b/arduino/hardware/ace/avr/cores/avr/main.cpp deleted file mode 100644 index 3881bbd..0000000 --- a/arduino/hardware/ace/avr/cores/avr/main.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: main.cpp - * Author: Zhao Yanbai - * 2018-06-14 20:21:33 Thursday CST - * Description: none - * ------------------------------------------------------------------------ - */ -#include - -void init_timer0(); -void init_timer1(); -void init_tasks(); - -void init() { - cli(); - init_timer0(); - init_timer1(); - init_tasks(); - sei(); -} - -int main() -{ - init(); - - uint8_t pin = 13; - set_digital_pin_mode(pin, OUTPUT); - digital_write(pin, LOW); - - uint8_t state = LOW; - while(1) { - state = state == LOW ? HIGH : LOW; - digital_write(pin, state); - delay(1000); - } - - - return 0; -} diff --git a/arduino/hardware/ace/avr/cores/avr/timer.cpp b/arduino/hardware/ace/avr/cores/avr/timer.cpp deleted file mode 100644 index b101177..0000000 --- a/arduino/hardware/ace/avr/cores/avr/timer.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ------------------------------------------------------------------------ - * File Name: timer.cpp - * Author: Zhao Yanbai - * 2018-06-15 18:31:24 Friday CST - * Description: none - * ------------------------------------------------------------------------ - */ - -#include - - -volatile unsigned long timer0_overflow_count = 0; -volatile unsigned long timer0_millis = 0; -static unsigned char timer0_fract = 0; - -unsigned long millis() -{ - unsigned long m; - uint8_t oldSREG = SREG; - - // disable interrupts while we read timer0_millis or we might get an - // inconsistent value (e.g. in the middle of a write to timer0_millis) - cli(); - m = timer0_millis; - SREG = oldSREG; - - return m; -} - -unsigned long micros() { - unsigned long m; - uint8_t oldSREG = SREG, t; - - cli(); - m = timer0_overflow_count; - - t = TCNT0; - if ((TIFR0 & _BV(TOV0)) && (t < 255)) { - m++; - } - SREG = oldSREG; - - return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); -} - -void delay(unsigned long ms) -{ - uint32_t start = micros(); - while (ms > 0) { - yield(); - while ( ms > 0 && (micros() - start) >= 1000) { - ms--; - start += 1000; - } - } -} - - -void init_timer0() { - // on the ATmega168, timer 0 is also used for fast hardware pwm - // (using phase-correct PWM would mean that timer 0 overflowed half as often - // resulting in different millis() behavior on the ATmega8 and ATmega168) - sbi(TCCR0A, WGM01); - sbi(TCCR0A, WGM00); - - // set timer 0 prescale factor to 64 - sbi(TCCR0B, CS01); - sbi(TCCR0B, CS00); - - // enable timer 0 overflow interrupt - sbi(TIMSK0, TOIE0); -} - -extern "C" void TIMER0_OVF_vect() __attribute__ ((signal,used, externally_visible)); -void TIMER0_OVF_vect() -{ - unsigned long m = timer0_millis; - unsigned char f = timer0_fract; - - m += MILLIS_INC; - f += FRACT_INC; - if (f >= FRACT_MAX) { - f -= FRACT_MAX; - m += 1; - } - - timer0_fract = f; - timer0_millis = m; - - timer0_overflow_count++; -} - - -#if 0 -extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal,used, externally_visible)); -void TIMER1_COMPA_vect() { } -#endif diff --git a/arduino/hardware/ace/avr/platform.txt b/arduino/hardware/ace/avr/platform.txt deleted file mode 100644 index 0f4965b..0000000 --- a/arduino/hardware/ace/avr/platform.txt +++ /dev/null @@ -1,130 +0,0 @@ - -# Arduino AVR Core and platform. -# ------------------------------ -# -# For more info: -# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification - -name=Ace Arduino AVR Boards -# version=1.6.21 - -# AVR compile variables -# --------------------- - -compiler.warning_flags=-w -compiler.warning_flags.none=-w -compiler.warning_flags.default= -compiler.warning_flags.more=-Wall -compiler.warning_flags.all=-Wall -Wextra - -# Default "compiler.path" is correct, change only if you want to override the initial value -compiler.path={runtime.tools.avr-gcc.path}/bin/ -compiler.c.cmd=avr-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -compiler.c.elf.flags={compiler.warning_flags} -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -compiler.c.elf.cmd=avr-gcc -compiler.S.flags=-c -g -x assembler-with-cpp -flto -MMD -compiler.cpp.cmd=avr-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -compiler.ar.cmd=avr-gcc-ar -compiler.ar.flags=rcs -compiler.objcopy.cmd=avr-objcopy -compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 -compiler.elf2hex.flags=-O ihex -R .eeprom -compiler.elf2hex.cmd=avr-objcopy -compiler.ldflags= -compiler.size.cmd=avr-size - -# This can be overridden in boards.txt -build.extra_flags= - -# These can be overridden in platform.local.txt -compiler.c.extra_flags= -compiler.c.elf.extra_flags= -compiler.S.extra_flags= -compiler.cpp.extra_flags= -compiler.ar.extra_flags= -compiler.objcopy.eep.extra_flags= -compiler.elf2hex.extra_flags= - -# AVR compile patterns -# -------------------- - -## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" - -## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" - -## Compile S files -recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" - -## Create archives -# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value -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 - -## 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" -recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" - -## Save hex -recipe.output.tmp_file={build.project_name}.hex -recipe.output.save_file={build.project_name}.{build.variant}.hex - -## Compute size -recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" -recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).* -recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* -recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* - -## Preprocessor -preproc.includes.flags=-w -x c++ -M -MG -MP -recipe.preproc.includes="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.includes.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" - -preproc.macros.flags=-w -x c++ -E -CC -recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{preprocessed_file_path}" - -# AVR Uploader/Programmers tools -# ------------------------------ - -tools.avrdude.path={runtime.tools.avrdude.path} -tools.avrdude.cmd.path={path}/bin/avrdude -tools.avrdude.config.path={path}/etc/avrdude.conf - -tools.avrdude.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA - -tools.avrdude.upload.params.verbose=-v -tools.avrdude.upload.params.quiet=-q -q -# tools.avrdude.upload.verify is needed for backwards compatibility with IDE 1.6.8 or older, IDE 1.6.9 or newer overrides this value -tools.avrdude.upload.verify= -tools.avrdude.upload.params.noverify=-V -tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} {upload.verify} -p{build.mcu} -c{upload.protocol} "-P{serial.port}" -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" - -tools.avrdude.program.params.verbose=-v -tools.avrdude.program.params.quiet=-q -q -# tools.avrdude.program.verify is needed for backwards compatibility with IDE 1.6.8 or older, IDE 1.6.9 or newer overrides this value -tools.avrdude.program.verify= -tools.avrdude.program.params.noverify=-V -tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" - -tools.avrdude.erase.params.verbose=-v -tools.avrdude.erase.params.quiet=-q -q -tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m - -tools.avrdude.bootloader.params.verbose=-v -tools.avrdude.bootloader.params.quiet=-q -q -tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m - -tools.avrdude_remote.upload.pattern=/usr/bin/run-avrdude /tmp/sketch.hex {upload.verbose} -p{build.mcu} - -tools.avrdude.upload.network_pattern="{network_cmd}" -address {serial.port} -port {upload.network.port} -sketch "{build.path}/{build.project_name}.hex" -upload {upload.network.endpoint_upload} -sync {upload.network.endpoint_sync} -reset {upload.network.endpoint_reset} -sync_exp {upload.network.sync_return} - -# USB Default Flags -# Default blank usb manufacturer will be filled in at compile time -# - from numeric vendor ID, set to Unknown otherwise -build.usb_manufacturer="Unknown" -build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' diff --git a/arduino/hardware/ace/avr/programmers.txt b/arduino/hardware/ace/avr/programmers.txt deleted file mode 100644 index c100e84..0000000 --- a/arduino/hardware/ace/avr/programmers.txt +++ /dev/null @@ -1,106 +0,0 @@ -avrisp.name=AVR ISP -avrisp.communication=serial -avrisp.protocol=stk500v1 -avrisp.program.protocol=stk500v1 -avrisp.program.tool=avrdude -avrisp.program.extra_params=-P{serial.port} - -avrispmkii.name=AVRISP mkII -avrispmkii.communication=usb -avrispmkii.protocol=stk500v2 -avrispmkii.program.protocol=stk500v2 -avrispmkii.program.tool=avrdude -avrispmkii.program.extra_params=-Pusb - -usbtinyisp.name=USBtinyISP -usbtinyisp.protocol=usbtiny -usbtinyisp.program.tool=avrdude -usbtinyisp.program.extra_params= - -arduinoisp.name=ArduinoISP -arduinoisp.protocol=arduinoisp -arduinoisp.program.tool=avrdude -arduinoisp.program.extra_params= - -arduinoisporg.name=ArduinoISP.org -arduinoisporg.protocol=arduinoisporg -arduinoisporg.program.tool=avrdude -arduinoisporg.program.extra_params= - -usbasp.name=USBasp -usbasp.communication=usb -usbasp.protocol=usbasp -usbasp.program.protocol=usbasp -usbasp.program.tool=avrdude -usbasp.program.extra_params=-Pusb - -parallel.name=Parallel Programmer -parallel.protocol=dapa -parallel.force=true -# parallel.delay=200 -parallel.program.tool=avrdude -parallel.program.extra_params=-F - -arduinoasisp.name=Arduino as ISP -arduinoasisp.communication=serial -arduinoasisp.protocol=stk500v1 -arduinoasisp.speed=19200 -arduinoasisp.program.protocol=stk500v1 -arduinoasisp.program.speed=19200 -arduinoasisp.program.tool=avrdude -arduinoasisp.program.extra_params=-P{serial.port} -b{program.speed} - -usbGemma.name=Arduino Gemma -usbGemma.protocol=arduinogemma -usbGemma.program.tool=avrdude -usbGemma.program.extra_params= -usbGemma.config.path={runtime.platform.path}/bootloaders/gemma/avrdude.conf - -## Notes about Dangerous Prototypes Bus Pirate as ISP -## Bus Pirate V3 need Firmware v5.10 or later -## Bus Pirate V4 need Firmware v6.3-r2151 or later -## Could happen that BP does not have enough current to power an Arduino board -## through the ICSP connector. In this case disconnect the +Vcc from ICSP connector -## and power Arduino board in the normal way. -buspirate.name=BusPirate as ISP -buspirate.communication=serial -buspirate.protocol=buspirate -buspirate.program.protocol=buspirate -buspirate.program.tool=avrdude -buspirate.program.extra_params=-P{serial.port} - -# STK500 firmware version v1 and v2 use different serial protocols. -# Using the 'stk500' protocol tells avrdude to try and autodetect the -# firmware version. If this leads to problems, we might need to add -# stk500v1 and stk500v2 entries to allow explicitely selecting the -# firmware version. -stk500.name=Atmel STK500 development board -stk500.communication=serial -stk500.protocol=stk500 -stk500.program.protocol=stk500 -stk500.program.tool=avrdude -stk500.program.extra_params=-P{serial.port} - -jtag3isp.name=Atmel JTAGICE3 (ISP mode) -jtag3isp.communication=usb -jtag3isp.protocol=jtag3isp -jtag3isp.program.protocol=jtag3isp -jtag3isp.program.tool=avrdude -jtag3isp.program.extra_params= - -jtag3.name=Atmel JTAGICE3 (JTAG mode) -jtag3.communication=usb -jtag3.protocol=jtag3 -jtag3.program.protocol=jtag3 -jtag3.program.tool=avrdude -# Set a bitclock of 0.1us (the fastest supported value). This should -# work regardless of the crystal used, since JTAG doesn't use the MCU -# clock but dictates its own clock. -jtag3.program.extra_params=-B0.1 - -atmel_ice.name=Atmel-ICE (AVR) -atmel_ice.communication=usb -atmel_ice.protocol=atmelice_isp -atmel_ice.program.protocol=atmelice_isp -atmel_ice.program.tool=avrdude -atmel_ice.program.extra_params=-Pusb diff --git a/arduino/ir/irrecv/irrecv.ino b/arduino/ir/irrecv/irrecv.ino deleted file mode 100644 index 445838d..0000000 --- a/arduino/ir/irrecv/irrecv.ino +++ /dev/null @@ -1,179 +0,0 @@ -//------------------------------------------------------------------------------ -// Include the IRremote library header -// -#include - -// HX1838(用金属包住头) 面对HX1838正面从左至右三个脚分别为 OUT、GND、VCC - -//------------------------------------------------------------------------------ -// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838) -// -int recvPin = 11; -IRrecv irrecv(recvPin); - -//+============================================================================= -// Configure the Arduino -// -void setup ( ) -{ - Serial.begin(9600); // Status message will be sent to PC at 9600 baud - irrecv.enableIRIn(); // Start the receiver -} - -//+============================================================================= -// Display IR code -// -void ircode (decode_results *results) -{ - // Panasonic has an Address - if (results->decode_type == PANASONIC) { - Serial.print(results->address, HEX); - Serial.print(":"); - } - - // Print Code - Serial.print(results->value, HEX); -} - -//+============================================================================= -// Display encoding type -// -void encoding (decode_results *results) -{ - switch (results->decode_type) { - default: - case UNKNOWN: Serial.print("UNKNOWN"); break ; - case NEC: Serial.print("NEC"); break ; - case SONY: Serial.print("SONY"); break ; - case RC5: Serial.print("RC5"); break ; - case RC6: Serial.print("RC6"); break ; - case DISH: Serial.print("DISH"); break ; - case SHARP: Serial.print("SHARP"); break ; - case JVC: Serial.print("JVC"); break ; - case SANYO: Serial.print("SANYO"); break ; - case MITSUBISHI: Serial.print("MITSUBISHI"); break ; - case SAMSUNG: Serial.print("SAMSUNG"); break ; - case LG: Serial.print("LG"); break ; - case WHYNTER: Serial.print("WHYNTER"); break ; - case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; - case PANASONIC: Serial.print("PANASONIC"); break ; - case DENON: Serial.print("Denon"); break ; - } -} - -//+============================================================================= -// Dump out the decode_results structure. -// -void dumpInfo (decode_results *results) -{ - // Check if the buffer overflowed - if (results->overflow) { - Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); - return; - } - - // Show Encoding standard - Serial.print("Encoding : "); - encoding(results); - Serial.println(""); - - // Show Code & length - Serial.print("Code : "); - ircode(results); - Serial.print(" ("); - Serial.print(results->bits, DEC); - Serial.println(" bits)"); -} - -//+============================================================================= -// Dump out the decode_results structure. -// -void dumpRaw (decode_results *results) -{ - // Print Raw data - Serial.print("Timing["); - Serial.print(results->rawlen-1, DEC); - Serial.println("]: "); - - for (int i = 1; i < results->rawlen; i++) { - unsigned long x = results->rawbuf[i] * USECPERTICK; - if (!(i & 1)) { // even - Serial.print("-"); - if (x < 1000) Serial.print(" ") ; - if (x < 100) Serial.print(" ") ; - Serial.print(x, DEC); - } else { // odd - Serial.print(" "); - Serial.print("+"); - if (x < 1000) Serial.print(" ") ; - if (x < 100) Serial.print(" ") ; - Serial.print(x, DEC); - if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one - } - if (!(i % 8)) Serial.println(""); - } - Serial.println(""); // Newline -} - -//+============================================================================= -// Dump out the decode_results structure. -// -void dumpCode (decode_results *results) -{ - // Start declaration - Serial.print("unsigned int "); // variable type - Serial.print("rawData["); // array name - Serial.print(results->rawlen - 1, DEC); // array size - Serial.print("] = {"); // Start declaration - - // Dump data - for (int i = 1; i < results->rawlen; i++) { - Serial.print(results->rawbuf[i] * USECPERTICK, DEC); - if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one - if (!(i & 1)) Serial.print(" "); - } - - // End declaration - Serial.print("};"); // - - // Comment - Serial.print(" // "); - encoding(results); - Serial.print(" "); - ircode(results); - - // Newline - Serial.println(""); - - // Now dump "known" codes - if (results->decode_type != UNKNOWN) { - - // Some protocols have an address - if (results->decode_type == PANASONIC) { - Serial.print("unsigned int addr = 0x"); - Serial.print(results->address, HEX); - Serial.println(";"); - } - - // All protocols have data - Serial.print("unsigned int data = 0x"); - Serial.print(results->value, HEX); - Serial.println(";"); - } -} - -//+============================================================================= -// The repeating section of the code -// -void loop ( ) -{ - decode_results results; // Somewhere to store the results - - if (irrecv.decode(&results)) { // Grab an IR code - dumpInfo(&results); // Output the results - dumpRaw(&results); // Output the results in RAW format - dumpCode(&results); // Output the results as source code - Serial.println(""); // Blank line between entries - irrecv.resume(); // Prepare for the next value - } -} diff --git a/arduino/ir/irsend/irsend.ino b/arduino/ir/irsend/irsend.ino deleted file mode 100644 index c30aac6..0000000 --- a/arduino/ir/irsend/irsend.ino +++ /dev/null @@ -1,46 +0,0 @@ -/* - * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend - * An IR LED must be connected to Arduino PWM pin 3. - * Version 0.1 July, 2009 - * Copyright 2009 Ken Shirriff - * http://arcfn.com - */ - - -// arduino ~3号引脚接940纳米发送头的长引脚 -// 短引脚接100欧电阻,再接GND - -#include - -IRsend irsend; - -void setup() -{ - Serial.begin(9600); -} - -void loop() { - - // 电信机顶盒用NEC发送 - - irsend.sendNEC(0xCD3201FE, 32); // 音量+ - Serial.println("+"); - delay(1000); - irsend.sendNEC(0xCD32817E, 32); // 音量- - Serial.println("-"); - delay(1000); - - - // 小米电视遥控 - int khz = 38; // 38kHz carrier frequency for the NEC protocol - // xiaomi increase volume signal - unsigned int ivs[] = {1000,600, 550,1150, 600,600, 550,900, 550,1150, 600,550, 600,600, 550,1450, 550,1200, 550,600, 550,600, 550}; - // xiaomi decrease volume signal - unsigned int dvs[] = {1050,550, 650,1050, 650,500, 650,800, 650,1100, 650,500, 650,500, 650,1400, 650,1350, 650,500, 650,800, 650}; - irsend.sendRaw(ivs, sizeof(ivs) / sizeof(ivs[0]), khz); - Serial.println("tv+"); - delay(1000); - irsend.sendRaw(dvs, sizeof(dvs) / sizeof(dvs[0]), khz); - Serial.println("tv-"); - delay(1000); -} diff --git a/arduino/library.properties b/arduino/library.properties new file mode 100644 index 0000000..321d3d4 --- /dev/null +++ b/arduino/library.properties @@ -0,0 +1,11 @@ +name=AceVest +version=0.0.1 +author=acevest +maintainer=acevest +sentence=sentence +paragraph=paragrah +category=Other +url=https://github.com/acevest/acecode +architectures=* +license=GPLv2 +includes=AceVest.h diff --git a/arduino/src/AceVest.h b/arduino/src/AceVest.h new file mode 100644 index 0000000..feb826d --- /dev/null +++ b/arduino/src/AceVest.h @@ -0,0 +1,33 @@ +/* + * ------------------------------------------------------------------------ + * File Name: AceVest.h + * Author: Zhao Yanbai + * 2018-12-14 12:14:38 Friday CST + * Description: none + * ------------------------------------------------------------------------ + */ + +#pragma once +#include + +#if defined(__GNUC__) && defined(__AVR__) +# define ACEVEST_FONT_SECTION(name) ACEVEST_SECTION(".progmem." name) +# define ACEVEST_PROGMEM PROGMEM +#endif + +#if defined(ESP8266) +# define ACEVEST_FONT_SECTION(name) __attribute__((section(".text." name))) +# define ACEVEST_PROGMEM +#endif + +#ifndef ACEVEST_FONT_SECTION +# define ACEVEST_FONT_SECTION(name) +#endif + + +extern const uint8_t font_acevest[] ACEVEST_FONT_SECTION("font_acevest"); + +typedef struct { + const char *name; + const char *pwd; +} WiFiItem_t; diff --git a/arduino/src/font.cpp b/arduino/src/font.cpp new file mode 100644 index 0000000..49e7db4 --- /dev/null +++ b/arduino/src/font.cpp @@ -0,0 +1,361 @@ +#include "AceVest.h" +const uint8_t font_acevest[11472] ACEVEST_FONT_SECTION("font_acevest") = + "{\0\4\2\5\5\5\5\6\20\20\0\376\12\376\13\377\1\270\3y\5{ \6\0@\217\2!\10A" + "Q\210\302AB\42\11\205H\214B\306M\0#\21FE\210JO\6\203D\244\305`\20\351\11\0$" + "\24GE\210Nh\240\210D$\241\331(\42\251\30\210\62\0%\27GE\210\206F\222(ID\24\251" + "X*!ID\22%\32\5\0&\24GE\210\312\246$S\21\22%\42\232\204(\221\221L\2'\7" + "\201P\214\302 (\15\203\315\207J\42\222\210\364&\222\11)\16\203\311\207B&\222\211\364\42\222\210\0" + "*\16\347\304\210NIE\233M\242IM\6+\15\347\304\210N\254f\60\310\304j\0,\11\202L\207" + "\202\42\241\0-\7$H\212\302 .\7BL\210\302 /\15FE\210VQU(\25\252J\1\60" + "\17FE\210\212&\222\10\371(\21\311H\0\61\14EI\210JF\222\10\365\311@\62\20FE\210\306" + " \21\22\245\62\232PUj\60\63\22FE\210\306 \21\22\245\42\263\224H\224\30$\0\64\22FE" + "\210RH\223\210Td\22\231\304`\224\252\0\65\20FE\210\302A\252j K\245D\211A\2\66\20" + "FE\210\312$\224J\15\24!G\211A\2\67\14FE\210\302UQ\252(\325\4\70\21FE\210\306" + " \21\62J\14\22!G\211A\2\71\20FE\210\306 \21\62J\14T\215\42\23\0:\11\342\314\210" + "\302 \66\10;\13\42\315\207\302 \246H(\0<\11%I\210R\246\253\16=\11\246D\211\302=f" + "\60>\12%E\210B\252\233\216\0\77\17FE\210\306 \21\22\245BU\331T\4@\25FE\210\312" + "$#I(\22\213\210\42\242\210H\26\261A\0A\17FE\210\212&\322\42$\32\14D\216\2B\20" + "FE\210\302@\21\62\32,B\216\6\13\0C\17FE\210\306 \21\262\352H\224\30$\0D\17F" + "E\210\302 \222I\204\374&\61\210\0E\16FE\210\302A\252j\240H\265\32\14F\15FE\210\302" + "A\252j\240Hu\5G\20FE\210\306 \21\262*\31\204l\24\213\0H\14FE\210B\310\321`" + " \362(I\14EI\210\302@\22\352'\3\1J\17GE\210\312@\24\353I&\222\311l\0K\23" + "FE\210BH\223\210TdD\242D&R\223\10\5L\12FE\210B\252\277\32\14M\16FE\210" + "BH\64\31D\26\36\71\12N\22FE\210Bh\263QD\24\21IB\222\320\34\5O\15FE\210" + "\306 \21\362G\211A\2P\16FE\210\302@\21\62\32,R]\1Q\31g\305\207\306 \22J\204" + "\22\241D(\21J\204\22\11EB\42\31\344\4R\22FE\210\302@\21\62\32,\42\65\211L\42$" + "\12S\17FE\210\306 \21\62s$J\14\22\0T\13GE\210\302A&\326\337\0U\14FE\210" + "B\310\77J\14\22\0V\23GE\210B\312*\221\211d\42\231\212P\42\25\313\0W\16FE\210B" + "\310\13\27\223Ad$\12X\21FE\210BH\224\210\264\21i\42-B\242\0Y\20GE\210BJ" + "\225\310D\62\25\251X\67\0Z\14FE\210\302UQ\257R\203\1[\12\203\321\207\302 \322\77\31\134" + "\15FE\210B*V\25K\305\252\2]\12\203\305\207\302\244\177\62\10^\12f\304\214\212&\222\10\5" + "_\10'\304\207\302A\0`\10cH\215B\246\0a\17\6E\210\306 \21J%\6#\33\305\42b" + "\17fE\210B\252\305B#r\264Q,\0c\16\6E\210\306 \21Ru\224\30$\0d\15fE" + "\210V\213\205f\344\215b\21e\20\6E\210\306 \21\22\15\6\252\242\304 \1f\15eE\210\216$" + "T\62\220\204z\2g\25fE\207Vb\241Id\22\231\310&\65H\204D\211A\2h\15fE\210" + "B\252\305B#\362Q\0i\14eI\210J((\352\223\201\0j\15\245E\207R\241\250\217$\21\11" + "\0k\22fE\210B\252M\42R\221\21%\62\221\232D(l\12eI\210\206\250\177\62\20m\24\7" + "E\210\302B\21\211H\42\222\210$\42\211H\42\222\2n\13\6E\210Bb\241\21\371(o\15\6E" + "\210\306 \21\362Qb\220\0p\20FE\207Bb\241\21\71\332(\26\251\24\0q\15FE\207\306B" + "\63\362F\261H\25r\14\6E\210Bb\241\21\251\272\2s\16\6E\210\306 \21\222\71J\14\22\0" + "t\14EE\210J\250d \11u%u\13\6E\210B\310o\24\213\0v\15\6E\210B\310(\21" + "\351\215H\2w\23\7E\210BJ\22\221D$\21ID\22\221TX\0x\20\6E\210BH\224\210" + "dD\232H\42$\12y\17FE\207B\310\243D\304\42U\61H\0z\13\6E\210\302U\250W\203" + "\1{\17\203\315\207\306$\23ID\62\221D$#|\10\301Q\207\302\7\2}\20\203\311\207\202&\222" + "\210d\42\211H&\262\0~\13gD\214\206F\22\321(\0\177&\20B\7C\242\337#\364\4z\304" + "d\220\310L\22\241T$\61Hd&\211Pj\62H\14\366\4z\2=\242\77\200'\20B\7C\242" + "\337#\364\4z\304F\262\230$\42\211H\344 \21\31\204\42\211HQ$\261\320\23\350\11\364\210\376\0" + "\260\11\203H\215F\205\242\2\267\7BL\212\302 \0\0\0\10X\344\13\231\377\377 \34\15\206D\214" + "FF\223\310$$\2 \35\16\206D\214\202D\221Id\64\11\0 \42\13\245D\211\306\301\27\13\0" + " \60\27HA\210F(QR\21\311Db\271X\242$\321\27\232D\2 \61\25HA\210F,\221" + "J\304\42\42\303DI\242\237$*\0!\3\31\307A\210F*\21J\244r\203H(\21J\304:J" + "\204\42\203\4\0!\220\16\247D\211J*\65\30$r!\0!\221\15\305I\207Jf\321$\324\177\2" + "!\222\15\247@\211R.\61\30\244J\0!\223\16\305I\210J\250\377$Q\261\211\0!\226\16\306\304" + "\211\302 \42Jd\42\261\2!\227\17\306\304\211\312 \244ID*B)\0!\230\16\306\304\211B\254" + "$\223\10I\6\1!\231\17\306D\211V(\21\251\310\210\6\21\0\42\36\15\207\304\211\206E$\42\251" + "\260\0%\262\16\306\304\211\212H\63\210\14\22\203\7%\263\16\306\304\211\212H\23i\21\32\14\2%\266" + "\16\306\304\211\202h\20\31|\20\21\1%\267\16\306\304\211\202(!\311\134HD\0%\274\16\306\304\211" + "\302\27\203\310 #\222\0%\275\16\306\304\211\302A(\21i#\222\0%\300\15\306\304\211\222d\360A" + "d\20\22%\301\16\306\304\211\222D\261\331D\24!\1&\2\20\7E\211\312f\240\30\14\62\261V!" + "\0&a\22'E\210\206E$\242\262Jd*R\261\14\0&e\20'E\210\206\305\340\77H\14\64" + "\253X\6\60\1\12\204\314\11CH\243\11\60\2\14\204L\11\207\42\42I(\0N\0\10/@\13\303" + "\17N\3\24\356\301\7[\272\67\203\324@\64P\244;\353\335`\20N\7\35\317A\7\303\257\342\345\203" + "A\60\25L\345b\271X],\227\12\206b\211P\60\5N\11\21\217A\10\307\340A\236\233\301\201\236" + "'\203\17N\12\20\357\301\7[\274\347\203A\60\336\207\203\17N\13\25\357A\7\303\317\342\235d\63\321" + "P\62\25L\5\343\35\2N\26(\357\301\7[&\27\311\344\42\231\134$\223\213dB\203o\42\231\134" + "$\223\213dr\221L.\62\320\305\313\7\7\12\0N\34\37\15F\7W\270n\360 \224\215\4\63\271" + "Pnp\240KF\252\62\215*RE\211l\16N*\27\17B\7_<\235\310f\222\251\134U\250D" + "\225\322\305\373\35\0N-\31\13J\7W\264\325\340QH\24\22\205D!Qh\360 T\25m\5N" + ";\26\357\301\7[\36\220\7\16\36\4\343-\7\7\312xw\203\17N]!\17B\7W\274\351\340 " + "\31J\206\222\241`*\230\12\246r\261LY&\222\313$\222\3\71\0N\214\15O\301\10\313\340@\317" + "\237\14>N\224\35\317\301\7\307\340A.\336tp\20L\5S\301T\60\225\213\345b\271Xf\360\1" + "N\250\36\17B\7[\36\220\33|\217\31\234\345b\271\330\340\36\65\70\10k\325\361p\42\35\4N\256" + "&\17B\7[\36\20\34<\310\243\6\203`*\70\30\344Q\203\7\212\260h\240\211e\242\231d\250D" + "\25\32\16\4N\277(\17B\7S\274b\60\20\5S\271\224,\246\212%B\261H(\231\211f\242\221" + "\134&\222\313Dr\231\314`\240\311\2N\360\62\16B\7S:\223LH\6\231H&\222\211d\42\21" + "I&\22\221d\42\211\222LDR\23\311D\62\221L$\221Pd\42\222D(\222\211\365\15\0O\17" + "*\17B\7Se(\221\13ER%\251:\305\340 \242\212%R%\241D.\224\310\205\22\271LY" + "\246,\222\252\310\205\224\1O )\17B\7Se(\31\12F\6\203T\235(\250\30\34$\212b\221" + "L\64\62\30\244\202\251LY(\221K\5c\271X\10O&*\17B\7Se(\231I\344B\211\134" + "\246J\222\12)r\212\232&\231H.\223\10f\224\231h&\25\312\244B\241\301(\13OM%\17B" + "\7S&\32J\206\202\361\304\340F-\314$\42\251H\253\232\262LY\246,\23\311\305r\203\67Y\0" + "OS+\17B\7Se(\31\12\246\202\211\301\215*'Z%B\243H&Q\226I\224EZ%\22" + "\3EHT\223\12\246\202\251\24\0O\213:\16B\7O\62\223\314$\6\232H&\224\210dB\211\204" + "f\220\250\320D\22\11E$\223(\211H\22%\25\235$\62\221D$\25IDB\251H&\26\251J" + "D\22\271\4\0O\341)\17B\7Se*\230\30\334\304\323\232\301 #Nd#\231\301 \24\257\31" + "\14B\231T(\223\12e\6\203P&\225\0P\31\64\17B\7O<\62\30\244\202\241D.\224\30\34" + "(\24\221\240\42\222KT\14\6\241\204&\227\10\345\22\203\3I\42\224Kd\22\261P&\225I\205\22" + ":\1P>\63\17B\7O<\64\30d\22\251\222P,\222\31H$\231\22\311\242'\231DM$\223" + "\250\211d\22\65\221D\67\21I\242&\22\212\345\22\241X\246\252\0PO/\16B\7O(\230\312%" + "\6'u\221\272\204dp!\11&\42\321\310\340$\242(\251\350\244\42\61\30H\22\235Tt\22\221$" + "JjR\2QF+\16F\7S&\231Ie\232\324DB\211L\42\225\310$\63:M\42\225\310D" + "\62\221LE\246\60T\23*I\205\22\271\301\32QI$\17B\7_\62T\225\11\305\42\231\134\244\66" + "\67\370*\23\315D\63\321L\62\324\233T(\222\33\14\322\0QK#\17B\7_<\67\370.\236\34" + "\34\210\222\241d(\31\32\34\350\62\321L\62\24L\205\42\261\320p Qk \356E\7c\62\223\314" + "$\63\311L\62\223\14\345R\271T.\226\312\245\202\231d&\232\10\7Qm\34\357\301\7[\36\220\7" + "\304\363\260\301\367T\231h(\30\313U\5C\321H\66\1Qs\36\17B\7O\256,\227\312\303\6\7" + "\312x\335\340\273t\42\234\310f\222\251\230N\242\25Qy+\17B\7S*\31JfR\203ob\271" + "X\273H&\222)\311d\6\231A.\326.\21J\204\62\221Ld\260\30\354b\11\0Q\205\42\15F" + "\7[\270l\360@\225R\245T)Q\42$\212d\64\241\210$\226P\344\22Z\313\204\64\1Q\254 " + "\17B\7W<=\30\310r\251D\252\246v\252\221\351$Z\325\36\240\7\4\367\0= \5Q\372!" + "\15F\7[\70\27*\11\225\204JB%\203\3](\27\216\245R\252\224*\245J\15\36\210\3R\6" + "$\17B\7g\64\23\15\5S\271\252d&\233\210\14\6\232T(\31J\206\202\251`*\27+J\304" + "\312\0R)/\16B\7_*\65\10%\6\272T(\222\12ER\241\310\340 \21\11\211\42\231\204&" + "\222I\224\364\42\322(\222\310\344D\271TE*\226\0RM.\17B\7O\256,\227\12\15\276\207\14" + "T\241L\244(\23)\32H\212\62\221\242L\244h )\312\244B\231T(Q\223\10ER\31\0R" + "\233\33\14F\7W\266\331\340U\177\24\13\305\62\271L.\22\312$b\211\302\10\0R\237(\16B\7" + "g\272h\60\210\344\62\203A&\225\251\312Te\252\62E\65\241\232A\42\64\320\244\22\251\262L\42\226" + "\212\0R\250/\16B\7g:\65\320\244\263\203A\62\63\30H\62\221X&\22\313DR\241D$\23" + "Jd\42\241\301 \221Jd\22\251X&\21KE\0S\5$\356\301\7S:<\270\312\205\202\231\304" + "`\322(\222\12ER\241Hj\60IU\244b\225\231dhp\20S\27+\17B\7W&\232\211f" + "\242\231\262L$\63\320$\202\31e&\232\211f\242\231h&\224\331\204\6\221L(\221\11\15TI\0" + "SA\17\17B\7_\274w\203\357\342\375\35\0SC\22\17B\7ov \32\314\273\33|\27\357w" + "\0SW(\17B\7_<\67\370.\36\34<\210TEj\232D\6\203HUI\252$\61\270\210\244" + "JR%\251L\42\22\215\0S`\36\15J\7W\270x\60P\205\333\15\16$\311H\62\222\214$#" + "\311\310\340@\222\214\0Sa\32\17B\7[<>\30\4\343\205\203\317\342%\331L\64\224L\5\343\205" + "\0Sg\60\16F\7gh\60P\204\42\251P$\25\212\244B\203AD\223\212$\42\251HE*\222" + "\31\14$\31I*\24I\205\42\251\320`\240H\27\1S\205!\357A\7\313\340A$\336bp \211" + "\345b\271X.\226\213\345b\271X],\225H\345b\0S\213%\357A\7\313\340A$\236\12\246\202" + "\251`*\230\30\34dR\301T\60\25I\325\204R\231\262\134b\360 \16S\225\65\357A\7\313\340A" + "$\236\30\210\62\211L\42\222Id\22\221L\242\223L\242\223L\242\223L\242\223L\242\223L\223L$" + "\221\212d\42\241HM$Q\22\214\0S\230(\357A\7\313\340A$\36\31\334D\62M\62M\6\67" + "\221L\223L\223\301M,\27\313E\6'\271X.\225\31\34\10S\232-\357A\7\313\340A$\36\31" + "\14D\221X(\62\30\210\42\261Pd\60\20\305#\203\201(\230\312\305\22\203\3E.\226J\244r\61" + "\0S\250\62\357A\7\313\340A$\31\32\14\62\241d(\61\10UD\22\203I\42\22\252\210\204*\6" + "\211H(\227\10%\42\241\22U&\264\251\30%\42\231X\6S\321$\16F\7[\62S\225\11e*" + "\7\317\302\351\301@\225H\225\204j\252B\211T,\25K$\65\242\235\0S\360\37\15F\7W\70[" + "U\227I&\6\17\22\321<\340Q.\224\13\345B\271\320\340(\27\1S\363!\17B\7[\274p\360" + "U<\35O\17\16B\211\134&\222\213dr\261\134,\27\33\234\345\42\0S\367\33\357A\7\317\340," + "\27\313\305r\261\301=f\360Q:>\70o\233H\247\0T\16#\17B\7ov\240\32H\343\361\301" + "\233x\213\301@\225\210\205\42\261P$\226)\213\204\6\3],\2T\21\37\15F\7W\266r\360@" + "k\63\320hj\64\65\232\32M\215f\240\321\324h\225\11i\2T+#\17B\7_<\235\310f\222" + "\211LL\223\221\250R\242\301 ]\71\70\313\305r\261\134lp\226\313\0T/!\16B\7_<\70" + "\70\320$\63\311L\62\63\70\320\244[\14N\352\42u\211LN\64\270\312\5Vh,\357A\7\313@" + "\62\320\224d\232d\62\3\311@\30\311f\62\203\317\22Q\215L'\321J\6\222\201\246$\323$\223\31" + "H\6\12\0V\333\35\255\305\7\303\7\232\32M\215\246FS\243\251\221\204\62\222\324@\221\234j\7\337" + "\6V\355%\355E\7\303\7Z\311`\20\321Z\14.\64\221\220&\22\322DB\222L$!\311D\22" + "\212\324B;\370\66W\37\20\357\301\7_\274\227\203\3e\274\357\6\37Wj'\17B\7O<\63\30" + "\204b\271X.\23\251\30L\22\221PEU,\27\31\334\304r\261\334(\264K\5\343E\0W\371(" + "\17B\7O*\30\313e\6\203P<\23\212\14&e\361\310\340&^\63\30\204\26\251\304(\25I\25" + "\16\6\301T\2X\344.\17B\7K,\27\31\334\304\63\213\311 \222h\224Y\214jR\221\301M(" + "\223\212\14n\64\65\213\301\201\42\25I\4\65\71EIR$Y\4.\17B\7O*\230\12\246\202\203" + "H\60\22\221e\42\211T&R\223\210\324$\42\211LQ\42\223\14%C\301D&\227\21\306\6\3\71" + "\0Y\17!\17B\7\307\340A.;\70\313\305\6g\271\330\340,\27\33\334\245\7W\211TM\355r" + "s\71Y\26'\16B\7O*\227\312\245r\251\330@\22\313DD%\211L(RQ\222i\221)*" + "\14\345R\261\252\134(\30\2Y'\32\17B\7_\274\273\301w\361t\42\234\310f\242\231d*W\225" + "\214h\5Y)\34\357A\7\313\340@\31o\67\370.\235\10'\262\231h&\231\312U%#Z\1Y" + "*\34\17B\7_\274\273\301w\361t\42\234\310f\242\231d\42\223\313T\205J\264\2Y\61!\17B" + "\7_\64\23\315D\63\321\301A\250\60\25\317\15\276K'\302\211l&\231\312\25)\25\0Y\306\60\17" + "B\7O<\64\30\365\42\222\30L*\62\221\242L\244(\23\31\34D*R\221\26\231\212H\243L*" + "\223\210\14\6\212L.\21\252Hg\0[W\32\17B\7[\36\20\34[\266(\17B\7[\36\20\34\270\12%C\301T.V\27\34<\10]\356\42\17B" + "\7S*\231\211\15\36\4\343\311\301\201\60\36\34|\225\256\30\14D\251\134\254.\71\70P\0]\362\27" + "\314\311\7\303\203l\223`$\30\31\34D\262MM\23\203\3\1^\25-\15F\7K,\25K\25\15" + "\24\203\201\242\225\242\225\242\225\242\225\242b\60P\264R\264R,R\221L*\222IE\62\203A$\223" + "\12^\70&\17B\7_\64S\27\251\32\70\320\244\202\251\134,\71\70H\205\222\241d(\66\370\60\336\31\0^\217&" + "\17B\7_\36\20\34<\210\304\63\203A(\230\252\210\325%\6\7\222X(\22\313\224\325\305r\251X" + "\42\35\3^\223%\17B\7_\36\20\34<\210\204\222\241\344\340Mi\244\60\221\11&\6G\251`*" + "\227\30\274\210\325\305c\0^\246'\17B\7_\36\20\34<\210d\312\62e\203\67\315\62e\231\201," + "\236\30\14T\221T\250&\225Z\205\64\252\335\0^\255.\17B\7_\36\20\34<\210\304\23\253I&" + "\61HER%\251\212\203A$\23JeB\251D\305`\220\310D\63\302Ld\60\320d\1_\0\42" + "\357A\7\307\340A\252\60\25L\5S\301Th\360Q*\230\12\246\202\251\134,\27\253K\5C\0_" + "\2#\357A\7\313\340 \25L\5S\203\203T\64\23\15\15\16\364\250\302Th\360Q*\27\253K\5" + "C\0_'\64\17B\7sd\240\32\244\22\203D.Q\222K\224\204\6\211\222PE$T\21\11U" + "DB\203DM,Q\23K$$\261D\223\224DQ\222(\351\42\12_\61-\355E\7\303\305`\25" + "K\305\6\203\304`\20K\305R\203\305`\221\211d\42\65\221\220J\242\310(\66\11M*\26I\204\22" + "\241X\4_:\62\360A\7\303@\62\30\304\42\251X$\225\31D\6\203L\60\225\32\134\244\62\25\3" + "E\246*\221\251J\14\256*S\221X*\223\210\304\6\13\315 \25_f#\16B\7[<\70\70P" + "\25fb\203'\351\134*\64K\214\312T!M\305(\223\23\205V\221!\0_\205+\17B\7Se" + "(\230\312e\6\3IQ\62\24L\14\16\42\272P\42\227\211$\6\7\231\134,\22\212e\312\62e\251" + "D\254\10_\252=\17B\7Ol\20J\14f\221P*\23*I\14\16\62\211P,\222\30\14\42\222" + "D*Q\222He\42\211\301 \23I\244\62\221\304`\220IDR\231D$\225\321\14\6\231P*\1" + "_\256\70\17B\7OQ*\321$\24I\224d*\332D\22\3\305 \23\213d\202\211\210b\260\350\60" + "\221\211\14\42\211L\244E&RQ\24\211HB\221\26\231D,\221\221e\2_\303#\317\301\7[\36" + "\220\7\304\263\361X(\222\313Dr\231H\60\221\11&\62\251\210(\25L%\7\33\0`\312\61\17B" + "\7O*\30\313E\6\67qm\242b\60\210$\62\251H\42\223JD\62\203A(\226\313D\22\251L" + "\244(\222i\21\312\24%r\251\24\0a\37\63\17B\7k\42\34\311\14\36Dr\261\304@\21\311\344" + "\42\231\304@Q\224\310DD\211L\244\42\62Pt\227\331\245r\301H&\24)\213\210\6\203H\0b" + "\20*\17B\7g\42\34\311\346\6\17\42\261\134,\27\313d\6\222L\223L\27\241LE(\23\212T" + "\324H\22\231\222DYhVb\67\35\14F\7W\70\233\33\34D\202\221`$\30\11F\6\7\221`" + "$[\232\215f\1b\77(\16B\7[<\70x\22\215D#\203'\241`*\67x\222If\222\231" + "\301 \222\211E\62\261D&\225\10\345\42\0b@.\17B\7[*\267y\226\12\246\202\3E\60\223" + "\30\14\42\231D&\224IdB\3E&\224\312\204R\231\252P&\25\212\244\352b\21\0b\311-\17" + "B\7O*\30\313\305r\331\201bp\23O\344B\222TF\223J(B\231T(\223\12eR\241H" + ",\27J$\6\7\221\60\0c\242.\17B\7K<\62\270\211\344\62\221\212Hb \311\244\62\251P" + ",\227\10\345\24\203\213Y.\65\13%\252\62\221\242\204&\263\210\325\245\0c\245/\17B\7O(\231" + "\12F\6\3Qv\260\10\245B\221Xbp\220I\5E\71\305\340E(\223\312\204R\241H,\245J" + "d$\242\210,\1e\66\60\16F\7O(\30JEB\251H&\26\311\14\6\222\242HEM\244\246" + "\244\246$!Jd\24\241D&\222\312\205\22\261LU$\25J\344\2eE.\17B\7O*\230\12" + "\246\202\241\330`\220\30\14\62E\251H\42\223\12e\62\3I\246\213P\246\42\224\11\245\62\25\241\201$" + "\323\42\225+ep\62\17B\7S\252\244Y\242&\230\32\333&*#u\231\252P\211*\245\213\347\0g:-\17B\7O<\63\220e\312\62\65\203E" + "&\226\251\322TM\62\241D\233P\242MI\246,S\222i\222\211\204\42\231Hj\223H\2g\317*" + "\16B\7O\254\253\134f\360 \221\312TE\64\251\310$\225h\61\30$\272\222dR\231\252LU\246" + "*\223\31\14\62U\1j*\60\17B\7O\263LYd\60P\14\26\231X\246,\61\70\210\250r\213" + "\301 \223HHj\22\221\301 \322\253\310`\220\212g\312\42\251\212\134\2k!*\17B\7c.\26" + "L\5S\203a\252$\24KD\202\211L\60\225Z%b\251D,\224I\205\62\251L*\24\311\245\222" + "\1k'.\16F\7cj\60I\345R\231\314@!)J\64\311D:\212\244B\211\242\212\232DF" + "\222Idr\211L,\23\31,\62\301T,\27kc\35\317\301\7\307\340A\60\336\64\23\315\14V\231" + "h&\232\211f\242\231h&\67\370\0k\317%\17B\7O|p\240\211\247\23\203\233H.\26\11\305" + "\62\65\203O\202\251L(\25\312\244\6\217\263\211t\12k\322$\17B\7_rp\240\214\16N\203\203" + "\7y\320\340,\22\212ej\6\237dB\251P&\65x\34\26\1k\324%\355\311\7[U,\25K" + "\205\22\251L$\25\311\14\24E)UY*\226\212\245R\22Ej\220I\311\6\3k\353'\17B\7" + "_p\360 \17\32\234\345b\203{\320\340\201\42,\33(\62\3\371`\65\220\17\6\211\304`\227\33\14" + "\4l\24\33\17B\7O<=x\223\216\14\6\232J\5Sy\324\340a*\230\12\246\202\251`$\221\314D" + "\343\205\0\202\222\32\357\301\7S*\230\12\15>J\5S\321< \67\370(\336\363\301A\2\202\257$" + "\357\301\7S*\230\12\15>J\5S\321< \17\310\306B\221\134&\22Ld\202\242T\60\225\34l" + "\0\202\261+\17B\7S*\230\12\15>J\345\201\231\262L$\26J\304D\262D(\26\311(#\211" + "T&\21IeB\251Lj\260\311\2\203I\36\17B\7W&\232I\15\276\312\344\201\203\263\134lp" + "\226\213\15Ns\203\357\342\355\0\206\360,\16B\7O(\30J\15\24\203U(\222\222H\42\203P$" + "\221\251\350IJR\221\312\14\256\62U\231\252\301e(\62x\20\211\6\210L%\17B\7S<\62\30" + "\204\322%\361tdp\42K%b\241H,\27\313\305r\261\134,\27J\344R)\0\211\177+\357A" + "\7\303\257\62\321L\64\223\33\34\210\42\231H(\222\211\204\42\231H(\222\211\204\22\251\221\60\224\14%" + "C\203\3Q\62\2\211\322)\15B\7S\70;\30\210r\231\134&\61\70\220\204JB%\203\3I\250" + "$T\62\70\220\204*R\241D*\222\220&\0\211\343\64\17B\7O<\64\330\14B\221L$\24i" + "\224h\61PdB\211\242T\242$\221\32H\6\232D\223T\242(\65P\14\6\221DQI\42\324M" + "H\224\1\213\241#\17B\7g.\26L\5S\361\252Abp\220I\5S\301T\60\25L\5\23\231" + "\240(\230\212\247\0\213\357*\357A\7Gh\60\10eR\241L*\70\30\344!\7\67\261\134,\227\30" + "\34Hb\271T\42\226\310$b\232\252L*\227\23\213\367.\17B\7g,W\62\270\211e\7\203l" + "j\62\70\210\304\63\203A(\223\12e\6\203P&\25J$\6\203\220$\25\312T\4C\31\0\214\67" + "$\17B\7S*\30\253\11\265\212\204\22\331L\62\25\323I\264\232\301Y.\226\213\345b\271\330\340," + "\227\1\215%\61\17B\7gl\240\211e\312\22%\271D\311`\220\350(\223H(\62\25%\231\212\222" + "LEM\42\224\250I\304Z\204\22\251HM\213T\42\225\13\215k\63\17B\7S*\230\12\246R\203" + "\305@\226\12\246B\203Ab\60\310$\62\211X\42\223\10%\22n\22\375$\221ID\332$R\221F" + "\211\222\232\222\210\6\215u.\17B\7S<\230\312\204\42\203I&U\21K%\42\203A(\27K%" + "R\211P\42\225\10%&\231\212L(\223\310&\264\221\301s\0\215\363\67\17B\7g\42\64\320$B" + "\231\212P&\321$\221\211(J\6\232\204\252\42\226J\250B\212\222\304\242I\242*\21J\244\22\241D" + "(R\221\230\224\14B\231H,\65\217f\33\17B\7[\274r\360 \226\216D\63\311Prp\240\214" + "\347\6\337\305\333\1\217\320#\317\301\7Kf\60H\305\363\24\203\213A*\30Jf\312\42\251\212\301Q" + "$\26J'\262\231\301A\0\217\333,\357\301\7c$U\22\13Eb\221\301@\31\311F\62\203P$" + "\226\30\34dB\221X(\22\313\224e\312\42\241T\42\233\31\34\4\220\0/\357\301\7\333`\20\312\244" + "JR%\203A\60\25LE\6\221\301 \25\251\11E\62\211T$\24\213$\62\251\210*\24\211e\22" + "\331\314\340 \220\1+\20B\7[.\222*\22eb\271\350\340\66\65\210\5c\301\304\340@\23\13\246" + "\22\271P&\226I\205\22u\221LR\65\70\10\220\37)\357\301\7g.\26L\14\216R\331\301 \30" + ")\31DZE\6\203Th\227I\224EZ%\62E\251\134\42\233\31\34\4\221\315\37\357\301\7ov" + " \32\314s\203\357\242\203\263L\331\340,S\66\70M\16\16\224\271\301\7\221\317\42\357A\7\317\340," + "\27\33\234\345\62\203\357\61\203\263L\331\340,S\66\70\215\16N\203\203\7\11\0\224\237*\16B\7O" + "\254\325 \224\312\205R\203\201b\220\210\324\224\324\224D\6\203D\244&\63\30dJjb\25\241\230*" + "V\235\1\225\177\42\17B\7S<\226K\5C\311L\64\222\215\16>J\204#\331L\64\224\214\24&" + "B\62\235(\12\225\350\22\15F\7G:\62\30H\222Z\377\227\11i\2\225\364%\15F\7G:\62" + "\30H\222Z\315@\243\251\321\324hj\64\3\215\246FS\243\251\321\14\64ZeB\232\0\226\63*\355" + "E\7\303@\230I\14\6\222*I\225\42\223\222TI\252\64\211\301@\223Hi\22\251E$\245\310\244" + "T)\325`\240*\226;\62\356E\7\303@\61\230d\22\241H\243H\243H\42\63\230\64\212\64\212d" + "\22\241H&\61\230d\22\241\210\42\22\212$\62\241H*\24\311\14\16\324\0\226M\61\16F\7_l" + " \211e\42\203E\244(RQ\222I\244D\221\210Id\23\331\204j\22\203A\42\23\12)jB\211" + "\310\340 \30\12\206\202!\0\226\234\67\16F\7gh\240\30\14\22\231H&R\224\310D\22\203\203D" + "\66\22\31\14\22\221\252D&\61\30$\62\211T\42\223\30\14\22\212T(\21\31\34\4C\301P\60\4" + "\226\350&\357A\7\303\357\342\205\203\7\221TI\252\244E&\222IDZ\225\264\310D\62\211H\253\222" + "T&\21\211F\0\226\352$\17B\7\313\340@\31\34 -#include - -SoftwareSerial btSerial(2, 4); // RX, TX - - -IRsend irsend; -const int ledPin = 5; - - -const int xiaomiRawCodeLen = 23; -enum { - XIAOMI_RAWCODE_POWER, - XIAOMI_RAWCODE_RETURN, - XIAOMI_RAWCODE_SUBMIT, - XIAOMI_RAWCODE_VOLUME_DEC, - XIAOMI_RAWCODE_VOLUME_INC, - - XIAOMI_RAWCODE_UP, - XIAOMI_RAWCODE_DOWN, - XIAOMI_RAWCODE_LEFT, - XIAOMI_RAWCODE_RIGHT, - XIAOMI_RAWCODE_MENU, - XIAOMI_RAWCODE_HOME, - - // ... - XIAOMI_RAWCODE_MAX_INX -}; - - -unsigned int xiaomiRawCode[][xiaomiRawCodeLen] = { - // power - {1100, 500, 650, 500, 650, 1400, 650, 1350, 650, 500, 650, 1400, 650, 500, 650, 1350, 650, 550, 650, 1350, 650, 1350, 650}, - // return - {950, 650, 500, 1200, 550, 650, 550, 850, 550, 1250, 500, 650, 450, 650, 550, 900, 550, 1500, 500, 1250, 500, 900, 550}, - // submit - {1000, 600, 550, 1200, 550, 600, 550, 900, 550, 1150, 600, 600, 550, 600, 550, 1450, 550, 900, 550, 600, 550, 1500, 550}, - // decrease volume signal - {1050, 550, 650, 1050, 650, 500, 650, 800, 650, 1100, 650, 500, 650, 500, 650, 1400, 650, 1350, 650, 500, 650,800, 650}, - // increase volume signal - {1000, 600, 550, 1150, 600, 600, 550, 900, 550, 1150, 600, 550, 600, 600, 550, 1450, 550, 1200, 550, 600, 550,600, 550}, - - // 上 - {1100, 500, 600, 1150, 650, 500, 600, 850, 650, 1050, 650, 550, 650, 500, 650, 800, 650, 800, 650, 1050, 650, 1400, 650}, - // 下 - {1050, 550, 600, 1150, 600, 550, 600, 850, 650, 1050, 650, 550, 600, 550, 600, 850, 650, 1050, 650, 1100, 650, 500, 650}, - // 左 - {1000, 600, 600, 1150, 550, 600, 550, 900, 550, 1200, 550, 600, 550, 600, 550, 1200, 550, 1450, 550, 900, 550, 900, 550}, - // 右 - {1000, 600, 550, 1200, 550, 600, 550, 900, 550, 1150, 600, 600, 550, 600, 550, 1450, 550, 600, 600, 600, 550, 1150, 550}, - // Menu - {1000, 600, 550, 1200, 550, 600, 550, 900, 550, 1200, 550, 600, 550, 600, 550, 900, 550, 600, 550, 1200, 550, 1150, 600}, - // Home - {1000, 600, 550, 1200, 550, 600, 550, 900, 550, 1150, 600, 600, 550, 600, 550, 1150, 600, 600, 550, 900, 550, 1150, 550} -}; - -void setup() -{ - Serial.begin(9600); - btSerial.begin(9600); -} - -void BlinkLed(int pin) { - pinMode(pin, OUTPUT); - digitalWrite(pin, HIGH); - delay(200); - digitalWrite(pin, LOW); - delay(200); - digitalWrite(pin, HIGH); - delay(200); - digitalWrite(pin, LOW); - pinMode(pin, INPUT); -} - -void SendXiaoMiSignal(int inx, const char *msg) { - - // 小米电视遥控 - const int khz = 38; // 38kHz carrier frequency for the NEC protocol - irsend.sendRaw(xiaomiRawCode[inx], xiaomiRawCodeLen, khz); - Serial.print("XiaoMi Signal: "); - Serial.println(msg); -} - -void loop() { - - int cmd = -1; - - if(btSerial.available() <= 0) { - delay(10); - return; - } - - cmd = btSerial.read(); - Serial.print("Received Cmd: " ); - Serial.println(cmd); - - - switch(cmd) { - case 0: - SendXiaoMiSignal(XIAOMI_RAWCODE_POWER, "power"); - break; - case 1: - SendXiaoMiSignal(XIAOMI_RAWCODE_SUBMIT, "submit"); - break; - - case 2: - SendXiaoMiSignal(XIAOMI_RAWCODE_RETURN, "return"); - break; - - case 3: - SendXiaoMiSignal(XIAOMI_RAWCODE_UP, "up"); - break; - - case 4: - SendXiaoMiSignal(XIAOMI_RAWCODE_DOWN, "down"); - break; - - case 5: - SendXiaoMiSignal(XIAOMI_RAWCODE_LEFT, "left"); - break; - - case 6: - SendXiaoMiSignal(XIAOMI_RAWCODE_RIGHT, "right"); - break; - - case 7: - irsend.sendNEC(0xCD32619E, 32); // 电信机顶盒频道- - Serial.println("tvbox channel-"); - break; - case 8: - irsend.sendNEC(0xCD32A15E, 32); // 电信机顶盒频道+ - Serial.println("tvbox channel+"); - break; - - - case 9: - SendXiaoMiSignal(XIAOMI_RAWCODE_MENU, "menu"); - break; - - case 10: - SendXiaoMiSignal(XIAOMI_RAWCODE_HOME, "home"); - break; - - case 11: - SendXiaoMiSignal(XIAOMI_RAWCODE_VOLUME_DEC, "tv volume -"); - break; - case 12: - SendXiaoMiSignal(XIAOMI_RAWCODE_VOLUME_INC, "tv volume +"); - break; - - case 13: - irsend.sendNEC(0xCD32817E, 32); // 电信机顶盒音量- - Serial.println("tvbox volume-"); - break; - case 14: - irsend.sendNEC(0xCD3201FE, 32); // 电信机顶盒音量+ - Serial.println("tvbox volume+"); - break; - - default: - Serial.print("error code: "); - Serial.println(cmd); - BlinkLed(ledPin); - break; - } - btSerial.write("OK:"); - btSerial.write(cmd); - BlinkLed(ledPin); -}