Skip to content

Commit

Permalink
a strawman model101 core for the Adafruit nrf platform that compiles …
Browse files Browse the repository at this point in the history
…but does not yet work
  • Loading branch information
obra committed Nov 15, 2023
1 parent 41e38fa commit 960eeda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

#ifdef ARDUINO_NRF52840_ITSYBITSY

#include "kaleidoscope/device/keyboardio/Model101.h"

#include <Arduino.h> // for PROGMEM
#include <Wire.h> // for Wire
#include "kaleidoscope/driver/keyscanner/Base_Impl.h" // For Base<>

#include "kaleidoscope/device/keyboardio/Model101.h"
#include "kaleidoscope/Runtime.h"

// #include "kaleidoscope/driver/keyscanner/Base_Impl.h" // For Base<>

// Here, we set up aliases to the device's KeyScanner and KeyScannerProps
// in the global namespace within the scope of this file. We'll use these
Expand All @@ -48,14 +48,18 @@ constexpr uint8_t KeyScannerProps::matrix_col_pins[matrix_columns];
//// `KeyScanner` here refers to the alias set up above, just like in the
//// `KeyScannerProps` case above.
template<>
KeyScanner::row_state_t KeyScanner::matrix_state_[KeyScannerProps::matrix_rows] = {};
KeyScanner::row_state_t
kaleidoscope::driver::keyscanner::Simple<kaleidoscope::device::keyboardio::Model101KeyScannerProps>::matrix_state_

template<>
uint32_t KeyScanner::next_scan_at_ = 0;
[KeyScannerProps::matrix_rows] = {};



#endif

template<>
uint32_t kaleidoscope::driver::keyscanner::Simple<kaleidoscope::device::keyboardio::Model101KeyScannerProps>::next_scan_at_ = 0;



} // namespace keyboardio
} // namespace device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct cRGB {
#include "kaleidoscope/device/Base.h"
#include "kaleidoscope/driver/bootloader/Base.h"
#include "kaleidoscope/driver/hid/Base.h"
#include "kaleidoscope/driver/keyboardio/Model101Side.h"
#include "kaleidoscope/driver/keyscanner/Simple.h"
#include "kaleidoscope/driver/led/Base.h"
#include "kaleidoscope/driver/mcu/Base.h"
Expand All @@ -52,87 +51,20 @@ struct Model101StorageProps : public kaleidoscope::driver::storage::BaseProps {
};


struct Model101LEDDriverProps : public kaleidoscope::driver::led::BaseProps {
static constexpr uint8_t led_count = 64;
static constexpr uint8_t key_led_map[] PROGMEM = {
// clang-format off
3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60,
2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61,
1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62,
0, 7, 8, 15, 16, 23, 31, 30, 33, 32, 40, 47, 48, 55, 56, 63,
// clang-format on
};
};

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model101LEDDriver : public kaleidoscope::driver::led::Base<Model101LEDDriverProps> {
public:
static void syncLeds();
static void setCrgbAt(uint8_t i, cRGB crgb);
static cRGB getCrgbAt(uint8_t i);
static void setBrightness(uint8_t brightness);
static uint8_t getBrightness();

static void enableHighPowerLeds();

private:
static bool isLEDChanged;
};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model101LEDDriver;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD



struct Model101KeyScannerProps : public kaleidoscope::driver::keyscanner::SimpleProps {

static constexpr uint8_t matrix_rows = 4;
static constexpr uint8_t matrix_columns = 16;
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
static constexpr uint8_t matrix_row_pins[matrix_rows] = {A0, A1, A2, A3};
static constexpr uint8_t matrix_col_pins[matrix_columns] = {A4, A5, SCK, MOSI, MISO, 1,0,2, 22,23, 5, 6, 9, 10, 11, 12};

#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
};




#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model101KeyScanner : public kaleidoscope::driver::keyscanner::Simple<Model101KeyScannerProps> {
private:
typedef Model101KeyScanner ThisType;

public:
static void setup();
static void scanMatrix();
static void readMatrix();
static void actOnMatrixScan();

static bool isKeyswitchPressed(KeyAddr key_addr);
static uint8_t pressedKeyswitchCount();

static bool wasKeyswitchPressed(KeyAddr key_addr);
static uint8_t previousPressedKeyswitchCount();

static void setKeyscanInterval(uint8_t interval);
static void enableScannerPower();
static void disableScannerPower();

protected:
static driver::keyboardio::keydata_t leftHandState;
static driver::keyboardio::keydata_t rightHandState;
static driver::keyboardio::keydata_t previousLeftHandState;
static driver::keyboardio::keydata_t previousRightHandState;

static void actOnHalfRow(uint8_t row, uint8_t colState, uint8_t colPrevState, uint8_t startPos);
};
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model101KeyScanner;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD


// If we need to override HID props:
struct Model101HIDProps : public kaleidoscope::driver::hid::BaseProps {
//typedef kaleidoscope::driver::hid::base::AbsoluteMouseProps AbsoluteMouseProps;
Expand All @@ -144,11 +76,11 @@ struct Model101Props : public kaleidoscope::device::BaseProps {
typedef Model101HIDProps HIDProps;
typedef kaleidoscope::driver::hid::Base<HIDProps> HID;

typedef Model101LEDDriverProps LEDDriverProps;
typedef Model101LEDDriver LEDDriver;
typedef kaleidoscope::driver::led::BaseProps LEDDriverProps;
typedef kaleidoscope::driver::led::Base<LEDDriverProps> LEDDriver;

typedef Model101KeyScannerProps KeyScannerProps;
typedef Model101KeyScanner KeyScanner;
typedef kaleidoscope::driver::keyscanner::Simple<KeyScannerProps> KeyScanner;

typedef Model101StorageProps StorageProps;
typedef kaleidoscope::driver::storage::Base<StorageProps> Storage;
Expand All @@ -160,19 +92,14 @@ struct Model101Props : public kaleidoscope::device::BaseProps {
typedef kaleidoscope::driver::mcu::Base<MCUProps> MCU;
};

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD

class Model101 : public kaleidoscope::device::Base<Model101Props> {
public:
auto serialPort() -> decltype(Serial) & {
return Serial;
}
static void rebootBootloader();
static void enableHardwareTestMode();
static void rebootBootloader() {};
};

#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

} // namespace keyboardio
} // namespace device

Expand Down

0 comments on commit 960eeda

Please sign in to comment.