;;;-*- Mode: Lisp; Package: cl-user -*- (in-package :cl-user) ; AVR (defparameter *title-avr-nano* #"/* uLisp AVR-Nano Release ~a - www.ulisp.com David Johnson-Davies - www.technoblogy.com - ~a Licensed under the MIT license: https://opensource.org/licenses/MIT */"#) (defparameter *header-avr-nano* #" // Lisp Library const char LispLibrary[] PROGMEM = ""; // Compile options #define checkoverflow // #define resetautorun #define printfreespace // #define printgcs // #define sdcardsupport // #define lisplibrary #define assemblerlist // #define lineeditor // #define vt100 // Includes // #include "LispLibrary.h" #include #include #include #include #include #if defined(sdcardsupport) #include #define SDSIZE 172 #else #define SDSIZE 0 #endif"#) (defparameter *workspace-avr-nano* #" // Platform specific settings #define WORDALIGNED __attribute__((aligned (2))) #define OBJECTALIGNED __attribute__((aligned (4))) #define BUFFERSIZE 22 /* longest builtin name + 1 */ #if defined(ARDUINO_AVR_UNO) #define WORKSPACESIZE (320-SDSIZE) /* Objects (4*bytes) */ #define EEPROMSIZE 1024 /* Bytes */ #define STACKDIFF 1 #define CPU_ATmega328P #elif defined(ARDUINO_AVR_NANO_EVERY) #define WORKSPACESIZE (1060-SDSIZE) /* Objects (4*bytes) */ #define EEPROMSIZE 256 /* Bytes */ #define STACKDIFF 160 #define CPU_ATmega4809 #elif defined(ARDUINO_AVR_ATmega4809) /* Curiosity Nano using MegaCoreX */ #define Serial Serial3 #define WORKSPACESIZE (1065-SDSIZE) /* Objects (4*bytes) */ #define EEPROMSIZE 256 /* Bytes */ #define STACKDIFF 320 #define CPU_ATmega4809 #elif defined(ARDUINO_AVR_ATtiny3227) #define WORKSPACESIZE (514-SDSIZE) /* Objects (4*bytes) */ // #define EEPROMSIZE 256 /* Bytes */ #define STACKDIFF 1 #define CPU_ATtiny3227 #elif defined(__AVR_AVR64DD28__) #include #define WORKSPACESIZE (1440-SDSIZE) /* Objects (4*bytes) */ #define FLASHWRITESIZE 6144 /* Bytes */ #define STACKDIFF 1 #define CPU_AVR64DD28 #else #error "Board not supported!" #endif"#) (defparameter *watchdog-avr-nano* #" // Watchdog void watchdogenable (int interval) { int i = 5; while (interval) { interval = interval>>1; i++; } wdt_enable(i); } void watchdogreset () { wdt_reset(); }"#) (defparameter *check-pins-avr-nano* #" // Check pins - these are board-specific not processor-specific void checkanalogread (int pin) { #if defined(ARDUINO_AVR_UNO) if (!(pin>=0 && pin<=5)) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_NANO_EVERY) if (!((pin>=14 && pin<=21))) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_ATmega4809) /* MegaCoreX core */ if (!((pin>=22 && pin<=33) || (pin>=36 && pin<=39))) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_ATtiny3227) if (!((pin>=0 && pin<=3) || (pin>=6 && pin<=7) || (pin>=10 && pin<=11) || pin==18)) error(invalidpin, number(pin)); #endif } void checkanalogwrite (int pin) { #if defined(ARDUINO_AVR_UNO) if (!(pin==3 || pin==5 || pin==6 || (pin>=9 && pin<=11))) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_NANO_EVERY) if (!(pin==3 || pin==5 || pin==6 || pin==9 || pin==10)) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_ATmega4809) /* MegaCoreX core */ if (!((pin>=16 && pin<=19) || (pin>=38 && pin<=39))) error(invalidpin, number(pin)); #elif defined(ARDUINO_AVR_ATtiny3227) if (!((pin>=0 && pin<=1) || (pin>=9 && pin<=11) || pin==20)) error(invalidpin, number(pin)); #endif }"#) (defparameter *note-avr-nano* #" // Note #if defined(CPU_ATtiny3227) || defined(CPU_AVR64DD28) const int scale[] PROGMEM = {4186,4435,4699,4978,5274,5588,5920,6272,6645,7040,7459,7902}; #else const uint8_t scale[] PROGMEM = {239,226,213,201,190,179,169,160,151,142,134,127}; #endif void playnote (int pin, int note, int octave) { #if defined(CPU_ATmega328P) if (pin == 3) { DDRD = DDRD | 1<6) error(PSTR("octave out of range"), number(oct)); OCR2A = pgm_read_byte(&scale[note%12]) - 1; TCCR2B = 0<8) error(PSTR("octave out of range"), number(oct)); tone(pin, scale[note%12]>>prescaler); #elif defined(CPU_AVR64DD28) int oct = octave + note/12; int prescaler = 8 - oct; if (prescaler<0 || prescaler>8) error(PSTR("octave out of range"), number(oct)); tone(pin, pgm_read_word(&scale[note%12])>>prescaler); #endif } void nonote (int pin) { #if defined(CPU_ATmega4809) || defined(CPU_ATtiny3227) || defined(CPU_AVR64DD28) noTone(pin); #else (void) pin; TCCR2B = 0< 0) { sleep(); secs--; } WDTCSR = 1<