Skip to content

Commit 8e623c1

Browse files
committed
Buncha fixex
1 parent 8c10142 commit 8e623c1

13 files changed

Lines changed: 971 additions & 527 deletions

File tree

megaavr/cores/megatinycore/Arduino.h

Lines changed: 116 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@
2929
#define CLOCK_TUNE_START (USER_SIGNATURES_SIZE - 12)
3030

3131
#include "core_devices.h"
32-
/* Gives names to all the timer pins - relies on core_devices.h being included first.*/
33-
/* These names look like:
34-
* PIN_TCD0_WOC_DEFAULT
35-
* PIN_TCA0_WO5_ALT3
36-
* and so on.
37-
* They are #defines. Pins that don't exist are #defined as NOT_A_PIN.
38-
* TCA and TCD only currently */
32+
3933
#include <avr/pgmspace.h>
4034
#include <avr/interrupt.h>
4135

@@ -82,7 +76,7 @@
8276
void check_constant_pin(__attribute__((unused))pin_size_t pin) {
8377
return;
8478
}
85-
#endif // Intentionally outside of the above #if so that your console gets fucking spammed with this warning.
79+
#endif // Intentionally outside of the above #_if so that your console gets fucking spammed with this warning.
8680
// The linker errors you turned off LTO to better understand will still be at the bottom.
8781
#warning "LTO is disabled. digitalWriteFast(), digitalReadFast(), pinModeFast() and openDrainFast() are unavailable, delayMicroseconds() for short delays and delay() with millis timing disabled is less accuratetest. Unsupported forms of 'new' compile without errors (but always return a NULL pointer). Additionally, functions which normally generate a compile error when passed a value that is known to be invalid at compile time will not do so. The same is true of functions which are not valid with the currently selected tools submenu options."
8882
#warning "This mode is ONLY for debugging LINK-TIME ERRORS that are reported by the linker as being located at .text+0, and you can't figure out where the bug is from other information it provides. As noted above, while this may make compilation succeed, it will only turn compile-time errors into incorrect runtime behavior, which is much harder to debug. As soon as the bug that forced this to be used is fixed, switch back to the standard platform.txt!"
@@ -219,7 +213,7 @@
219213
#define _ADC_LOWLAT_VAL 0x04
220214
#define _ADC_ENABLE_VAL 0x10
221215
#define _ADC_ENABLE_CTRL 0x20
222-
#define _ADC_STANDBY_VAL 0X40
216+
#define _ADC_STANDBY_VAL 0x40
223217
#define _ADC_STANDBY_CTRL 0x80
224218
#define PGA_OFF_ONCE 0x01
225219
#define PGA_KEEP_ON 0x02
@@ -725,7 +719,7 @@ See Ref_Analog.md for more information of the representations of "analog pins".
725719
#define portOutputRegister(P) ((volatile uint8_t *)(&portToPortStruct(P)->OUT))
726720
#define portInputRegister(P) ((volatile uint8_t *)(&portToPortStruct(P)->IN ))
727721
#define portModeRegister(P) ((volatile uint8_t *)(&portToPortStruct(P)->DIR))
728-
#if defined(PORTA_EVGENCTRL) //Ex-series only - this all may belong in the Event library anyway, but since the conditional is never met, this code is never used.
722+
#if defined(PORTA_EVGENCTRLA) //Ex-series only - this all may belong in the Event library anyway, but since the conditional is never met, this code is never used.
729723
#define portEventRegister(p) ((volatile uint8_t *)(&portToPortStruct(P)->EVGENCTRL))
730724
uint8_t _setRTCEventChan(uint8_t val, uint8_t chan);
731725
uint8_t _setEventPin(uint8_t pin, uint8_t number); // preliminary thought - pass a pin number, it looks up port, and from there the event control register and sets it.
@@ -927,123 +921,123 @@ void _pinconfigure(uint8_t pin, uint16_t pin_config);
927921
void pinConfigure(uint8_t digital_pin, uint16_t pin_config);
928922

929923
#ifdef __cplusplus
930-
typedef enum : uint16_t
931-
{
932-
// OUTPUT
933-
PIN_DIR_SET = 0x0001,
934-
PIN_DIRSET = 0x0001,
935-
PIN_DIR_OUTPUT = 0x0001,
936-
PIN_DIR_OUT = 0x0001,
937-
// INPUT
938-
PIN_DIR_CLR = 0x0002,
939-
PIN_DIRCLR = 0x0002,
940-
PIN_DIR_INPUT = 0x0002,
941-
PIN_DIR_IN = 0x0002,
942-
// TOGGLE INPUT/OUTPUT
943-
PIN_DIR_TGL = 0x0003,
944-
PIN_DIRTGL = 0x0003,
945-
PIN_DIR_TOGGLE = 0x0003,
946-
// HIGH
947-
PIN_OUT_SET = 0x0004,
948-
PIN_OUTSET = 0x0004,
949-
PIN_OUT_HIGH = 0x0004,
950-
// LOW
951-
PIN_OUT_CLR = 0x0008,
952-
PIN_OUTCLR = 0x0008,
953-
PIN_OUT_LOW = 0x0008,
954-
// CHANGE/TOGGLE
955-
PIN_OUT_TGL = 0x000C,
956-
PIN_OUTTGL = 0x000C,
957-
PIN_OUT_TOGGLE = 0x000C,
958-
//Interrupt disabled but input buffer enabled
959-
PIN_ISC_ENABLE = 0x0080,
960-
PIN_INPUT_ENABLE = 0x0080,
961-
// Interrupt on change
962-
PIN_ISC_CHANGE = 0x0090,
963-
PIN_INT_CHANGE = 0x0090,
964-
// Interrupt on rising edge
965-
PIN_ISC_RISE = 0x00A0,
966-
PIN_INT_RISE = 0x00A0,
967-
// Interrupt on falling edge
968-
PIN_ISC_FALL = 0x00B0,
969-
PIN_INT_FALL = 0x00B0,
970-
// Interrupt and input buffer disabled
971-
PIN_ISC_DISABLE = 0x00C0,
972-
PIN_INPUT_DISABLE = 0x00C0,
973-
// Interrupt enabled with sense on low level
974-
PIN_ISC_LEVEL = 0x00D0,
975-
PIN_INT_LEVEL = 0x00D0,
976-
// PULLUP ON
977-
PIN_PULLUP_ON = 0x0100,
978-
PIN_PULLUP = 0x0100,
979-
PIN_PULLUP_SET = 0x0100,
980-
// PULLUP OFF
981-
PIN_PULLUP_OFF = 0x0200,
982-
PIN_PULLUP_CLR = 0x0200,
983-
// PULLUP TOGGLE
984-
PIN_PULLUP_TGL = 0x0300,
985-
PIN_PULLUP_TOGGLE = 0x0300,
986-
PIN_NOPULLUP = 0x0200,
987-
// Pin Input Level Control
988-
PIN_INLVL_TTL = 0x1000,
989-
PIN_INLVL_ON = 0x1000,
990-
PIN_INLVL_SET = 0x1000,
991-
PIN_INLVL_SCHMITT = 0x2000,
992-
PIN_INLVL_OFF = 0x2000,
993-
PIN_INLVL_CLR = 0x2000, // alias
994-
// PIN INVERT ON
995-
PIN_INVERT_ON = 0x4000,
996-
PIN_INVERT_SET = 0x4000,
997-
// PIN INVERT OFF
998-
PIN_INVERT_OFF = 0x8000,
999-
PIN_INVERT_CLR = 0x8000,
1000-
// PIN_INVERT_TOGGLE
1001-
PIN_INVERT_TGL = 0xC000,
1002-
PIN_INVERT_TOGGLE = 0xC000
1003-
} pin_configure_t;
1004-
1005-
/**
1006-
* @brief Helper functions to catch the last argument in the pincfg recursion loop
1007-
*
1008-
* @param mode Mode parameter
1009-
* @return pin_configure_t
1010-
*/
1011-
1012-
1013-
inline pin_configure_t _pincfg(const pin_configure_t mode) {
1014-
return mode;
1015-
}
924+
typedef enum : uint16_t
925+
{
926+
// OUTPUT
927+
PIN_DIR_SET = 0x0001,
928+
PIN_DIRSET = 0x0001,
929+
PIN_DIR_OUTPUT = 0x0001,
930+
PIN_DIR_OUT = 0x0001,
931+
// INPUT
932+
PIN_DIR_CLR = 0x0002,
933+
PIN_DIRCLR = 0x0002,
934+
PIN_DIR_INPUT = 0x0002,
935+
PIN_DIR_IN = 0x0002,
936+
// TOGGLE INPUT/OUTPUT
937+
PIN_DIR_TGL = 0x0003,
938+
PIN_DIRTGL = 0x0003,
939+
PIN_DIR_TOGGLE = 0x0003,
940+
// HIGH
941+
PIN_OUT_SET = 0x0004,
942+
PIN_OUTSET = 0x0004,
943+
PIN_OUT_HIGH = 0x0004,
944+
// LOW
945+
PIN_OUT_CLR = 0x0008,
946+
PIN_OUTCLR = 0x0008,
947+
PIN_OUT_LOW = 0x0008,
948+
// CHANGE/TOGGLE
949+
PIN_OUT_TGL = 0x000C,
950+
PIN_OUTTGL = 0x000C,
951+
PIN_OUT_TOGGLE = 0x000C,
952+
//Interrupt disabled but input buffer enabled
953+
PIN_ISC_ENABLE = 0x0080,
954+
PIN_INPUT_ENABLE = 0x0080,
955+
// Interrupt on change
956+
PIN_ISC_CHANGE = 0x0090,
957+
PIN_INT_CHANGE = 0x0090,
958+
// Interrupt on rising edge
959+
PIN_ISC_RISE = 0x00A0,
960+
PIN_INT_RISE = 0x00A0,
961+
// Interrupt on falling edge
962+
PIN_ISC_FALL = 0x00B0,
963+
PIN_INT_FALL = 0x00B0,
964+
// Interrupt and input buffer disabled
965+
PIN_ISC_DISABLE = 0x00C0,
966+
PIN_INPUT_DISABLE = 0x00C0,
967+
// Interrupt enabled with sense on low level
968+
PIN_ISC_LEVEL = 0x00D0,
969+
PIN_INT_LEVEL = 0x00D0,
970+
// PULLUP ON
971+
PIN_PULLUP_ON = 0x0100,
972+
PIN_PULLUP = 0x0100,
973+
PIN_PULLUP_SET = 0x0100,
974+
// PULLUP OFF
975+
PIN_PULLUP_OFF = 0x0200,
976+
PIN_PULLUP_CLR = 0x0200,
977+
// PULLUP TOGGLE
978+
PIN_PULLUP_TGL = 0x0300,
979+
PIN_PULLUP_TOGGLE = 0x0300,
980+
PIN_NOPULLUP = 0x0200,
981+
// Pin Input Level Control
982+
PIN_INLVL_TTL = 0x1000,
983+
PIN_INLVL_ON = 0x1000,
984+
PIN_INLVL_SET = 0x1000,
985+
PIN_INLVL_SCHMITT = 0x2000,
986+
PIN_INLVL_OFF = 0x2000,
987+
PIN_INLVL_CLR = 0x2000, // alias
988+
// PIN INVERT ON
989+
PIN_INVERT_ON = 0x4000,
990+
PIN_INVERT_SET = 0x4000,
991+
// PIN INVERT OFF
992+
PIN_INVERT_OFF = 0x8000,
993+
PIN_INVERT_CLR = 0x8000,
994+
// PIN_INVERT_TOGGLE
995+
PIN_INVERT_TGL = 0xC000,
996+
PIN_INVERT_TOGGLE = 0xC000
997+
} pin_configure_t;
998+
999+
/**
1000+
* @brief Helper functions to catch the last argument in the pincfg recursion loop
1001+
*
1002+
* @param mode Mode parameter
1003+
* @return pin_configure_t
1004+
*/
1005+
1006+
1007+
inline pin_configure_t _pincfg(const pin_configure_t mode) {
1008+
return mode;
1009+
}
10161010

1017-
/**
1018-
* @brief Helper functions to catch the nth in the pincfg recursion loop
1019-
*
1020-
* @param digital_pin Arduino pin
1021-
* @param mode First "mode" parameter
1022-
* @param modes Nth "mode" parameter
1023-
* @return uint16_t pin configuration or'ed together
1024-
*/
1025-
template <typename... MODES>
1026-
uint16_t _pincfg(const pin_configure_t mode, const MODES&... modes) {
1027-
return mode | _pincfg(modes...);
1028-
}
1011+
/**
1012+
* @brief Helper functions to catch the nth in the pincfg recursion loop
1013+
*
1014+
* @param digital_pin Arduino pin
1015+
* @param mode First "mode" parameter
1016+
* @param modes Nth "mode" parameter
1017+
* @return uint16_t pin configuration or'ed together
1018+
*/
1019+
template <typename... MODES>
1020+
uint16_t _pincfg(const pin_configure_t mode, const MODES&... modes) {
1021+
return mode | _pincfg(modes...);
1022+
}
10291023

10301024

10311025

1032-
//void pinConfigure(const uint8_t pinNumber, const uint16_t mode, const MODES&... modes);
1026+
//void pinConfigure(const uint8_t pinNumber, const uint16_t mode, const MODES&... modes);
10331027

1034-
/**
1035-
* @brief Variadic template function for configuring a pin
1036-
*
1037-
* @param digital_pin Arduino pin number
1038-
* @param mode First "mode" parameter
1039-
* @param modes Nth "mode" parameter
1040-
*/
1041-
template <typename... MODES>
1042-
void pinConfigure(const uint8_t digital_pin, const pin_configure_t mode, const MODES&... modes) {
1043-
// Or-ing together the arguments using recursion
1044-
uint16_t pin_config = _pincfg(mode, modes...);
1045-
_pinconfigure(digital_pin, pin_config);
1046-
}
1028+
/**
1029+
* @brief Variadic template function for configuring a pin
1030+
*
1031+
* @param digital_pin Arduino pin number
1032+
* @param mode First "mode" parameter
1033+
* @param modes Nth "mode" parameter
1034+
*/
1035+
template <typename... MODES>
1036+
void pinConfigure(const uint8_t digital_pin, const pin_configure_t mode, const MODES&... modes) {
1037+
// Or-ing together the arguments using recursion
1038+
uint16_t pin_config = _pincfg(mode, modes...);
1039+
_pinconfigure(digital_pin, pin_config);
1040+
}
10471041
#endif // end
10481042

10491043

megaavr/cores/megatinycore/core_parameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#endif
1111
#endif
1212

13-
#if !(defined(MEGATINYCORE) || defined(DXCORE) || defined(ATTIYNCORE))
13+
#if !(defined(MEGATINYCORE) || defined(DXCORE) || defined(ATTINYCORE))
1414

1515
// This define can get black-hole'ed somehow (reported on platformio) likely the ugly syntax to pass a string define from platform.txt via a -D
1616
// directive passed to the compiler is getting mangled somehow, though I'm amazed it doesn't cause a compile error. But checking for defined(MEGATINYCORE)

megaavr/cores/megatinycore/dirty_tricks.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ Not enabled. Ugly ways to get delays at very small flash cost.
268268
* These allow you to perform surgery on a 16-bit values that already exist, where you wish to change the high or low byte
269269
* without altering the other byte. Amazingly, the compiler doesn't optimize this like you'd expect it to (likely because
270270
* of C type promotion rules).
271+
*
272+
* SK: isn't this the architecture specific stuff, which we know is poor for AVR? GCC compiles to an architecture agnostic intermediate form, optimizes that,
273+
* and then transforms that into the architecture specific output. The first part has gotten a ton of attention because it effects everything. Atmel used to pay
274+
* people to work on GCC. I do not belive that is still occurring, at least not to the extent it did. Pretty much all of these fall into two categories:
275+
* Either we're desperately scrambling for every last cycle, and using knowledge that the computer isn't permitted to, like knowing that we don't need to finish a math
276+
* opperation on a multi-byte datatype because we just need to low byte or know the high byte will be 0.
271277
*/
272278

273279
/************/
@@ -340,7 +346,13 @@ Not enabled. Ugly ways to get delays at very small flash cost.
340346
*
341347
* _makeFastPtr() should be used when you are only reading from that one address, or consecutive addresses starting there (eg, *ptr++ or *--ptr),
342348
* so it can use the X, Y or Z register.
343-
* _makeFastPtr_d() uses only X or Y register, and should be used if you expect to be accessing constant compile time known constant offsets
349+
* _makeFastPtr_d() uses only Y or Z register, and should be used if you expect to be accessing constant compile time known constant offsets
350+
*
351+
* Using STD or LDD, you can access an offset up to 64 bytesaway from where the pointer is aimed in the same timeas accessing that location, provided that the value is known at compile time.
352+
* This is good for accessing data in structs. Usually the compiler does an acceptable job of using efficient way of going about it. Occasionally the register allocator makes some regretable decisions, typically by , for example, and will generally use LDD/STD to load/store from
353+
*
354+
*
355+
*
344356
*
345357
*/
346358

megaavr/cores/megatinycore/wiring.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,10 @@ void restart_millis()
13591359
while (TCD0.STATUS & 0x01);
13601360
#elif (defined(MILLIS_USE_TIMERB0) || defined(MILLIS_USE_TIMERB1) || defined(MILLIS_USE_TIMERB2) || defined(MILLIS_USE_TIMERB3) || defined(MILLIS_USE_TIMERB4)) // It's a type b timer
13611361
_timer->CTRLB = 0;
1362+
#if defined(TCB_CTRLC)
1363+
// What the bloody hell was this added for?
1364+
_timer->CTRLC = 0;
1365+
#endif
13621366
#endif
13631367
init_millis();
13641368
#endif

0 commit comments

Comments
 (0)