first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
#include <avr/interrupt.h>
#include <TinyExternalInterrupt0.h>
#include <TinySleep.h>
void onInterrupt() {
// wakeup and do something
}
int main()
{
sei();
// interrupt when INT0 (pin 7) has LOW level (RISING or FALLING do not wake up from deep sleep)
ExternalInterrupt0.on(LOW, onInterrupt);
while (1) {
deepSleep();
}
return 0;
}

View File

@@ -0,0 +1,67 @@
#include <string.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <TinySleep.h>
#include <TinyTimer1Compare.h>
#include <TinyPinChangeB.h>
#include <TinyUartReader.h>
#include <TinyNmea.h>
struct NmeaData {
bool fresh; // custom data readiness indicator
char time[18]; // "hh:mm:ss DD/MM/YY"
};
// result data holder
NmeaData data;
// parser configuration array
NmeaParser config[] = {
// this function will be called for every term in ZDA statement
{{'Z','D','A'}, [](const char* term, const uint8_t index) {
// i.e. $GPZDA,201530.00,04,07,2002,00,00*60
switch (index) {
case 0: // time (term = "201530.00")
for (uint8_t i = 0, j = 0; i < 6; i+=2, j+=3) {
memcpy(&data.time[j], &term[i], 2);
}
data.time[2] = ':';
data.time[5] = ':';
data.time[8] = ' ';
break;
case 1: // day (term = "04")
memcpy(&data.time[9], &term[0], 2);
data.time[11] = '/';
break;
case 2: // month (term = "07")
memcpy(&data.time[12], &term[0], 2);
data.time[14] = '/';
break;
case 3: // year (term = "2002")
memcpy(&data.time[15], &term[2], 2);
data.time[17] = 0;
data.fresh = true;
break;
}
}}
};
TinyNmea nmea(config, sizeof(config));
int main() {
sei();
// continuously read from PB2 (pin 7) at 9600 baud using Timer1 in compare mode
uartReader.on(PB2, 9600, Timer1Compare, PinChangeB);
while (1) {
while (uartReader.inputAvailable()) {
// send each symbol to NMEA parser
nmea.next(uartReader.read());
}
if (data.fresh) {
data.fresh = false;
// make use of data.time value
}
idleSleep();
}
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <avr/interrupt.h>
#include <TinyTimer0Overflow.h>
#include <TinyTimer1Overflow.h>
void runOnTimer0() {
//
}
void runOnTimer1() {
//
}
int main() {
sei();
Timer0Overflow.on(0x3fc00, runOnTimer0);
Timer1Overflow.on(0x3fc000, runOnTimer1);
while (1) {
// do nothing
}
return 0;
}

View File

@@ -0,0 +1,27 @@
#include <avr/interrupt.h>
#include <TinySleep.h>
#include <TinyUart.h>
#include <TinyTimer1Compare.h>
#include <TinyPinChangeB.h>
// continuously read bytes from PB2 (pin 7) and repeat them to PB1 (pin 6)
// at 9600 baud using Timer1 in compare mode
int main() {
sei();
uart.on(PB2, PB1, 9600, Timer1Compare, PinChangeB);
while (1) {
if (uart.inputAvailable()) {
uart.write(uart.read());
}
idleSleep();
}
return 0;
}
/* Commented out because Arduino dumps ELF file into HEX file for flashing
// FUSES = {
// .low = 0xFF & FUSE_CKSEL1 & FUSE_CKSEL2 & FUSE_CKSEL3, // F_CPU: 16 MHz
// .high = 0xFF & FUSE_SPIEN & FUSE_EESAVE,
// .extended = 0xFF
// };
*/

View File

@@ -0,0 +1,18 @@
#include <avr/interrupt.h>
#include <Arduino.h>
#include <TinySerial.h>
#include <TinyTimer1Compare.h>
#include <TinyPinChangeB.h>
TinySerial serial(PB2, PB1, Timer1Compare, PinChangeB);
void setup() {
sei();
serial.begin(9600);
}
// continuously output on PB1 (pin 6) at 9600 baud using Timer1 in compare mode
void loop() {
delay(5000);
serial.print(F("this is a test\n"));
}

View File

@@ -0,0 +1,19 @@
#include <avr/interrupt.h>
#include <TinyUartReader.h>
#include <TinySleep.h>
#include <TinyTimer1Compare.h>
#include <TinyPinChangeB.h>
// continuously read from PB2 (pin 7) at 9600 baud using Timer1 in compare mode
int main() {
sei();
uartReader.on(PB2, 9600, Timer1Compare, PinChangeB);
while (1) {
if (uartReader.inputAvailable()) {
uint8_t value = uartReader.read();
// do something with the value
}
idleSleep();
}
return 0;
}

View File

@@ -0,0 +1,16 @@
#include <avr/interrupt.h>
#include <TinyUartWriter.h>
#include <TinySleep.h>
#include <TinyTimer1Compare.h>
#include <TinyPinChangeB.h>
// output "A"+<LF> on PB1 (pin 6) at 9600 baud using Timer1 in compare mode and then stop
int main() {
sei();
uartWriter.on(PB1, 9600, Timer1Compare);
uartWriter.write('A');
uartWriter.write(10);
while (uartWriter.outputRemaining()) idleSleep();
uartWriter.off();
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <avr/interrupt.h>
#include <TinyWatchdog.h>
#include <TinySleep.h>
int main() {
sei();
Watchdog.arm(9, [](){
// do something after 8 seconds (prescaler value of 9 translates to 8 seconds)
});
deepSleep();
// at this point the watchdog will interrupt the sleep
cli();
deepSleep();
}