Skip to content

Commit edb30f5

Browse files
authored
Merge pull request #650 from CapeLeidokos/pr_virtual_build_fix
Fixed virtual builds
2 parents 487d958 + a114f3c commit edb30f5

File tree

26 files changed

+177
-27
lines changed

26 files changed

+177
-27
lines changed

src/kaleidoscope/device/ATmega32U4Keyboard.h

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#pragma once
1919

20-
#ifdef __AVR__
20+
#if defined(__AVR__) || defined(KALEIDOSCOPE_VIRTUAL_BUILD)
2121

2222
#include <Arduino.h>
2323
#include "kaleidoscope/device/Base.h"
@@ -27,16 +27,44 @@
2727
#include "kaleidoscope/driver/storage/ATmega32U4EEPROMProps.h"
2828
#include "kaleidoscope/driver/storage/AVREEPROM.h"
2929

30-
#define ATMEGA32U4_KEYBOARD(BOARD_, BOOTLOADER_, ROW_PINS_, COL_PINS_) \
31-
struct BOARD_##Props : kaleidoscope::device::ATmega32U4KeyboardProps { \
32-
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps { \
33-
ATMEGA_KEYSCANNER_PROPS(ROW_PIN_LIST(ROW_PINS_), COL_PIN_LIST(COL_PINS_)); \
34-
}; \
35-
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner; \
36-
typedef kaleidoscope::driver::bootloader::avr::BOOTLOADER_ BootLoader; \
37-
}; \
30+
#define ATMEGA32U4_DEVICE_PROPS(BOARD_, BOOTLOADER_, ROW_PINS_, COL_PINS_) \
31+
struct BOARD_##Props : kaleidoscope::device::ATmega32U4KeyboardProps { \
32+
struct KeyScannerProps \
33+
: public kaleidoscope::driver::keyscanner::ATmegaProps \
34+
{ \
35+
ATMEGA_KEYSCANNER_PROPS(ROW_PIN_LIST(ROW_PINS_), \
36+
COL_PIN_LIST(COL_PINS_)); \
37+
}; \
38+
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;\
39+
typedef kaleidoscope::driver::bootloader::avr::BOOTLOADER_ BootLoader; \
40+
};
41+
42+
#define ATMEGA32U4_DEVICE(BOARD_) \
3843
class BOARD_: public kaleidoscope::device::ATmega32U4Keyboard<BOARD_##Props> {};
3944

45+
#define FORWARD(...) __VA_ARGS__
46+
47+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
48+
49+
#define ATMEGA32U4_KEYBOARD(BOARD_, BOOTLOADER_, ROW_PINS_, COL_PINS_) \
50+
ATMEGA32U4_DEVICE_PROPS(BOARD_, BOOTLOADER_, \
51+
FORWARD(ROW_PINS_), FORWARD(COL_PINS_)) \
52+
ATMEGA32U4_DEVICE(BOARD_)
53+
54+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
55+
56+
#define ATMEGA32U4_KEYBOARD(BOARD_, BOOTLOADER_, ROW_PINS_, COL_PINS_) \
57+
ATMEGA32U4_DEVICE_PROPS(BOARD_, BOOTLOADER_, \
58+
FORWARD(ROW_PINS_), FORWARD(COL_PINS_)) \
59+
/* Device definition omitted for virtual device builds. \
60+
* We need to forward declare the device name, though, as there are \
61+
* some legacy extern references to boards whose definition \
62+
* depends on this. \
63+
*/ \
64+
class BOARD_;
65+
66+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
67+
4068
namespace kaleidoscope {
4169
namespace device {
4270

@@ -46,13 +74,18 @@ struct ATmega32U4KeyboardProps : kaleidoscope::device::BaseProps {
4674
typedef kaleidoscope::driver::storage::AVREEPROM<StorageProps> Storage;
4775
};
4876

77+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
4978
template <typename _DeviceProps>
5079
class ATmega32U4Keyboard : public kaleidoscope::device::Base<_DeviceProps> {
5180
public:
5281
auto serialPort() -> decltype(Serial) & {
5382
return Serial;
5483
}
5584
};
85+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
86+
template <typename _DeviceProps>
87+
class ATmega32U4Keyboard;
88+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
5689

5790
}
5891
}

src/kaleidoscope/device/avr/pins_and_ports.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#pragma once
2323

24-
#ifndef __ASSEMBLER__
24+
#if !defined(__ASSEMBLER__) && !defined(KALEIDOSCOPE_VIRTUAL_BUILD)
2525
#include <avr/io.h>
2626
#endif
2727
#define PORT_SHIFTER 4 // this may be 4 for all AVR chips
@@ -55,13 +55,22 @@
5555
#define PINC_ADDRESS 0x3
5656
#define PINB_ADDRESS 0x6
5757
#define PINA_ADDRESS 0x9
58-
#else
58+
#elif !defined(KALEIDOSCOPE_VIRTUAL_BUILD)
5959
#error "Pins are not defined"
6060
#endif
6161

6262
/* I/O pins */
63+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
6364
#define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
64-
65+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
66+
#define PINDEF(port, pin) 0
67+
#define PORTA
68+
#define PORTB
69+
#define PORTC
70+
#define PORTD
71+
#define PORTE
72+
#define PORTF
73+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
6574

6675
#ifdef PORTA
6776
#define PIN_A0 PINDEF(A, 0)
@@ -124,7 +133,6 @@
124133
#define PIN_F7 PINDEF(F, 7)
125134
#endif
126135

127-
128136
/* converting pins to ports */
129137
enum { PIN_OFFSET, DDR_OFFSET, PORT_OFFSET};
130138

src/kaleidoscope/device/ez/ErgoDox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2525
*/
2626

27+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
2728
#ifdef ARDUINO_AVR_ERGODOX
2829

2930
#include <Kaleidoscope.h>
@@ -232,3 +233,4 @@ uint8_t ErgoDox::pressedKeyswitchCount() {
232233
kaleidoscope::device::ez::ErgoDox &ErgoDox = kaleidoscope_internal::device;
233234

234235
#endif
236+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

src/kaleidoscope/device/ez/ErgoDox.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
#include <Arduino.h>
3131

32-
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
33-
3432
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
3533

3634
struct cRGB {
@@ -42,6 +40,9 @@ struct cRGB {
4240
#include "kaleidoscope/driver/keyscanner/Base.h"
4341
#include "kaleidoscope/driver/bootloader/avr/HalfKay.h"
4442
#include "kaleidoscope/device/ATmega32U4Keyboard.h"
43+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
44+
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
45+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
4546

4647
namespace kaleidoscope {
4748
namespace device {
@@ -54,6 +55,7 @@ struct ErgoDoxProps : public kaleidoscope::device::ATmega32U4KeyboardProps {
5455
typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader;
5556
};
5657

58+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
5759
class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
5860
public:
5961
ErgoDox(void) {}
@@ -93,6 +95,9 @@ class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
9395
static void debounceRow(uint8_t change, uint8_t row);
9496
static void readMatrixRow(uint8_t row);
9597
};
98+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
99+
class ErgoDox;
100+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
96101

97102
#define PER_KEY_DATA_STACKED(dflt, \
98103
/* left hand, spatial positions */ \

src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
*/
2525

26+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
2627
#ifdef ARDUINO_AVR_ERGODOX
2728

2829
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
@@ -171,3 +172,4 @@ ErgoDoxScanner::reattachExpanderOnError() {
171172
}
172173

173174
#endif
175+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

src/kaleidoscope/device/ez/ErgoDox/i2cmaster.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Usage: API compatible with I2C Software Library i2cmaster.h
88
**************************************************************************/
99

10+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
1011
#ifdef ARDUINO_AVR_ERGODOX
1112

1213
#include <inttypes.h>
@@ -201,3 +202,4 @@ unsigned char i2c_readNak(void) {
201202
}/* i2c_readNak */
202203

203204
#endif
205+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

src/kaleidoscope/device/kbdfans/KBD4x.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
1819
#ifdef ARDUINO_AVR_KBD4X
1920

2021
#include <Kaleidoscope.h>
@@ -32,3 +33,4 @@ ATMEGA_KEYSCANNER_BOILERPLATE
3233
kaleidoscope::device::kbdfans::KBD4x &KBD4x = kaleidoscope_internal::device;
3334

3435
#endif
36+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

src/kaleidoscope/device/kbdfans/KBD4x.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
4242
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
4343
};
4444

45+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
4546
class KBD4x: public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {
4647
public:
4748
KBD4x() {
4849
mcu_.disableJTAG();
4950
mcu_.disableClockDivision();
5051
}
5152
};
53+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
54+
class KBD4x;
55+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
5256

5357
#define PER_KEY_DATA(dflt, \
5458
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \

src/kaleidoscope/device/keyboardio/Imago.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace keyboardio {
3333

3434
constexpr uint8_t ImagoLEDDriverProps::key_led_map[] PROGMEM;
3535

36+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
37+
3638
static constexpr uint8_t CMD_SET_REGISTER = 0xFD;
3739
static constexpr uint8_t CMD_WRITE_ENABLE = 0xFE;
3840
static constexpr uint8_t WRITE_ENABLE_ONCE = 0b11000101;
@@ -172,6 +174,8 @@ void Imago::setup() {
172174
kaleidoscope::device::ATmega32U4Keyboard<ImagoProps>::setup();
173175
}
174176

177+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
178+
175179
}
176180
}
177181
}

src/kaleidoscope/device/keyboardio/Imago.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct ImagoLEDDriverProps: public kaleidoscope::driver::led::BaseProps {
5151
};
5252
};
5353

54+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
5455
class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProps> {
5556
public:
5657
static void setup();
@@ -68,6 +69,9 @@ class ImagoLEDDriver : public kaleidoscope::driver::led::Base<ImagoLEDDriverProp
6869
static void setAllPwmTo(uint8_t);
6970
static void twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat);
7071
};
72+
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
73+
class ImagoLEDDriver;
74+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
7175

7276
struct ImagoProps : kaleidoscope::device::ATmega32U4KeyboardProps {
7377
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
@@ -82,10 +86,12 @@ struct ImagoProps : kaleidoscope::device::ATmega32U4KeyboardProps {
8286
typedef kaleidoscope::driver::bootloader::avr::Caterina BootLoader;
8387
};
8488

89+
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
8590
class Imago: public kaleidoscope::device::ATmega32U4Keyboard<ImagoProps> {
8691
public:
8792
void setup();
8893
};
94+
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
8995

9096
#define PER_KEY_DATA(dflt, \
9197
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, R0C12, R0C13, R0C14, R0C15, \

0 commit comments

Comments
 (0)