~jacqueline/reform

cc97be3ea68fd141b03fdb9b15d96c66cf306e2f — jacqueline 3 months ago 7fed460 + 68ebb36
Merge remote-tracking branch 'upstream/master'
M reform2-keyboard-fw/descriptors.c => reform2-keyboard-fw/descriptors.c +5 -10
@@ 40,24 40,19 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MediaControlReport[] =
	HID_RI_USAGE_PAGE(8, 0x0C), /* Consumer Page */
	HID_RI_USAGE(8, 0x01), /* Consumer Controls */
	HID_RI_COLLECTION(8, 0x01), /* Application */
		HID_RI_USAGE(8, 0xB0), /* Play */
		HID_RI_USAGE(8, 0xB1), /* Pause */
		HID_RI_USAGE(8, 0xB3), /* Fast Forward */
		HID_RI_USAGE(8, 0xB4), /* Rewind */
		HID_RI_USAGE(8, 0xB5), /* Next Track */
		HID_RI_USAGE(8, 0x70), /* Display Brightness Decrement */
		HID_RI_USAGE(8, 0x6F), /* Display Brightness Increment */
		HID_RI_USAGE(8, 0xB6), /* Previous Track */
		HID_RI_USAGE(8, 0xB7), /* Stop */
		HID_RI_USAGE(8, 0xCD), /* Play/Pause (toggle) */
		HID_RI_USAGE(8, 0xB5), /* Next Track */
		HID_RI_USAGE(8, 0xE2), /* Mute */
		HID_RI_USAGE(8, 0xE9), /* Volume Up */
		HID_RI_USAGE(8, 0xEA), /* Volume Down */
		HID_RI_USAGE(8, 0xE9), /* Volume Up */
		HID_RI_REPORT_SIZE(8, 0x01),
		HID_RI_REPORT_COUNT(8, 0x0B),
		HID_RI_REPORT_COUNT(8, 0x08),
		HID_RI_LOGICAL_MINIMUM(8, 0),
		HID_RI_LOGICAL_MAXIMUM(8, 1),
		HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
		HID_RI_REPORT_COUNT(8, 0x05),
		HID_RI_INPUT(8, HID_IOF_CONSTANT),
	HID_RI_END_COLLECTION(0),
};


M reform2-keyboard-fw/hid_report.c => reform2-keyboard-fw/hid_report.c +1 -1
@@ 67,7 67,7 @@ void hid_report_cmd(uint8_t* data) {
  else if (command == CMD_OLED_BITMAP) {
    matrix_render_direct(data+4);
  }
  else if (command == CMD_OLED_BITMAP) {
  else if (command == CMD_OLED_CLEAR) {
    gfx_clear();
    gfx_flush();
  }

M reform2-keyboard-fw/keyboard.c => reform2-keyboard-fw/keyboard.c +10 -21
@@ 101,28 101,17 @@ inline bool is_media_key(uint8_t keycode) {
  return (keycode>=HID_KEYBOARD_SC_MEDIA_PLAY);
}

bool get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) {
  bool media_key = false;
  if (keycode == HID_KEYBOARD_SC_MEDIA_MUTE) {
    if (mcr) mcr->Mute = 1;
    media_key = true;
  } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_UP) {
    if (mcr) mcr->VolumeUp = 1;
    media_key = true;
  } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN) {
    if (mcr) mcr->VolumeDown = 1;
    media_key = true;
  } else if (keycode == HID_KEYBOARD_SC_MEDIA_BACKWARD) {
    if (mcr) mcr->PreviousTrack = 1;
    media_key = true;
  } else if (keycode == HID_KEYBOARD_SC_MEDIA_FORWARD) {
    if (mcr) mcr->NextTrack = 1;
    media_key = true;
  } else if (keycode == HID_KEYBOARD_SC_MEDIA_PLAY) {
    if (mcr) mcr->PlayPause = 1;
    media_key = true;
void get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) {
  switch (keycode) {
  case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN: mcr->BrightnessDown = 1; break;
  case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP: mcr->BrightnessUp = 1; break;
  case HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK: mcr->PreviousTrack = 1; break;
  case HID_KEYBOARD_SC_MEDIA_PLAY: mcr->PlayPause = 1; break;
  case HID_KEYBOARD_SC_MEDIA_NEXT_TRACK: mcr->NextTrack = 1; break;
  case HID_KEYBOARD_SC_MEDIA_MUTE: mcr->Mute = 1; break;
  case HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN: mcr->VolumeDown = 1; break;
  case HID_KEYBOARD_SC_MEDIA_VOLUME_UP: mcr->VolumeUp = 1; break;
  }
  return media_key;
}

#define MAX_SCANCODES 6

M reform2-keyboard-fw/keyboard.h => reform2-keyboard-fw/keyboard.h +8 -8
@@ 25,6 25,10 @@
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)

// Reuse existing key codes
#define HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN HID_KEYBOARD_SC_MEDIA_RELOAD
#define HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP HID_KEYBOARD_SC_MEDIA_CALCULATOR

// Top row, left to right
#define MATRIX_DEFAULT_ROW_1 \
  KEY_ESCAPE,\


@@ 186,18 190,14 @@
// MediaController USB Report
typedef struct
{
  unsigned Play           : 1;
  unsigned Pause          : 1;
  unsigned FForward       : 1;
  unsigned Rewind         : 1;
  unsigned NextTrack      : 1;
  unsigned BrightnessDown : 1;
  unsigned BrightnessUp   : 1;
  unsigned PreviousTrack  : 1;
  unsigned Stop           : 1;
  unsigned PlayPause      : 1;
  unsigned NextTrack      : 1;
  unsigned Mute           : 1;
  unsigned VolumeUp       : 1;
  unsigned VolumeDown     : 1;
  unsigned RESERVED       : 5;
  unsigned VolumeUp       : 1;
} ATTR_PACKED USB_MediaReport_Data_t;

void setup_hardware(void);

M reform2-keyboard-fw/matrix_v.h => reform2-keyboard-fw/matrix_v.h +8 -8
@@ 37,15 37,15 @@ uint8_t matrix[KBD_MATRIX_SZ] = {
uint8_t matrix_fn[KBD_MATRIX_SZ] = {
  // Custom top row
  KEY_ESCAPE,
  KEY_F1,
  KEY_F2,
  HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN,
  HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP,
  KEY_F3,
  KEY_F4,
  KEY_F5,
  KEY_F6,
  HID_KEYBOARD_SC_MEDIA_BACKWARD,
  HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK,
  HID_KEYBOARD_SC_MEDIA_PLAY,
  HID_KEYBOARD_SC_MEDIA_FORWARD,
  HID_KEYBOARD_SC_MEDIA_NEXT_TRACK,
  HID_KEYBOARD_SC_MEDIA_MUTE,
  HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN,
  HID_KEYBOARD_SC_MEDIA_VOLUME_UP,


@@ 90,15 90,15 @@ uint8_t matrix_fn[KBD_MATRIX_SZ] = {
uint8_t matrix_fn_toggled[KBD_MATRIX_SZ] = {
  // Custom top row
  KEY_ESCAPE,
  KEY_F1,
  KEY_F2,
  HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN,
  HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP,
  KEY_F3,
  KEY_F4,
  KEY_F5,
  KEY_F6,
  HID_KEYBOARD_SC_MEDIA_BACKWARD,
  HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK,
  HID_KEYBOARD_SC_MEDIA_PLAY,
  HID_KEYBOARD_SC_MEDIA_FORWARD,
  HID_KEYBOARD_SC_MEDIA_NEXT_TRACK,
  HID_KEYBOARD_SC_MEDIA_MUTE,
  HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN,
  HID_KEYBOARD_SC_MEDIA_VOLUME_UP,

M reform2-lpc-fw/src/boards/reform2/board_reform2.c => reform2-lpc-fw/src/boards/reform2/board_reform2.c +4 -11
@@ 536,7 536,7 @@ void boardInit(void)

  // SPI0 connected to the main SOM (they're controller)
  ssp0Init();
  ssp0ClockSlow();
  ssp0ClockFast();

  // SPI chip select
  LPC_GPIO->DIR[1] |= (1 << 23);


@@ 988,19 988,12 @@ void handle_spi_commands() {

  // Host must wait while the LPC prepares response buffer
  // If host does not read 8 bytes the previous response buffer will be stuck in here. 
  uint8_t Dummy = Dummy;
  for (uint8_t i = 0; i < SSP0_FIFOSIZE; i++)
  {
    /* Move on only if TX FIFO not full. */
    // while ((LPC_SSP0->SR & SSP0_SR_TNF_MASK) == SSP0_SR_TNF_FULL);
    LPC_SSP0->DR = spiBuf[i];

    // while ( (LPC_SSP0->SR & SSP0_SR_RNE_MASK) == SSP0_SR_RNE_EMPTY );
    /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO
    on MISO. Otherwise, when sspReceive is called, previous data byte
    is left in the FIFO. */
    Dummy = LPC_SSP0->DR;
  }
  // Clear RX FIFO
  for (uint8_t i = 0; i < SSP0_FIFOSIZE; i++)
    spiBuf[i] = LPC_SSP0->DR;

  spi_cmd_state = ST_EXPECT_MAGIC;
  spi_command = 0;

M reform2-trackball-fw/Mouse.c => reform2-trackball-fw/Mouse.c +1 -1
@@ 317,7 317,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn

  *ReportSize = sizeof(USB_WheelMouseReport_Data_t);

  return true;
  return false;
}

/** HID class driver callback function for the processing of HID reports from the host.