gokul/macro-six-usbc

A six-key macro keyboard PCB paired with a separate physical enclosure.

Version
0.1.16
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone gokul/macro-six-usbc  # download the package files into ./macro-six-usbc
tsci add gokul/macro-six-usbc    # add it to your project as @tsci/gokul.macro-six-usbc

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

firmware/Descriptors.c

#include "Descriptors.h"
// pid.codes reserves 1209:0001 for testing; private in-house use only; obtain an authorized PID before product manufacture/distribution.
#ifndef USB_VID
#define USB_VID 0x1209
#endif
#ifndef USB_PID
#define USB_PID 0x0001
#endif
static const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = { HID_DESCRIPTOR_KEYBOARD(6) };
static const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsumerReport[] = {
 0x05,0x0c, 0x09,0x01, 0xa1,0x01,
 0x15,0x00, 0x25,0x01, 0x09,0xe9, 0x09,0xea, 0x09,0xe2,
 0x75,0x01, 0x95,0x03, 0x81,0x02,
 0x75,0x05, 0x95,0x01, 0x81,0x03, 0xc0
};
static const USB_Descriptor_Device_t PROGMEM Device = {
 .Header={sizeof(USB_Descriptor_Device_t),DTYPE_Device},
 .USBSpecification=VERSION_BCD(2,0,0), .Endpoint0Size=8,
 .VendorID=USB_VID,.ProductID=USB_PID,.ReleaseNumber=VERSION_BCD(0,1,0),
 .ManufacturerStrIndex=1,.ProductStrIndex=2,.SerialNumStrIndex=USE_INTERNAL_SERIAL,
 .NumberOfConfigurations=1
};
static const MacroConfiguration PROGMEM Config = {
 .Config={.Header={sizeof(USB_Descriptor_Configuration_Header_t),DTYPE_Configuration},
  .TotalConfigurationSize=sizeof(MacroConfiguration),.TotalInterfaces=2,
  .ConfigurationNumber=1,.ConfigAttributes=USB_CONFIG_ATTR_RESERVED,
  .MaxPowerConsumption=USB_CONFIG_POWER_MA(100)},
 .KeyboardInterface={.Header={sizeof(USB_Descriptor_Interface_t),DTYPE_Interface},
  .InterfaceNumber=0,.TotalEndpoints=1,.Class=HID_CSCP_HIDClass,
  .SubClass=HID_CSCP_BootSubclass,.Protocol=HID_CSCP_KeyboardBootProtocol},
 .KeyboardHID={.Header={sizeof(USB_HID_Descriptor_HID_t),HID_DTYPE_HID},
  .HIDSpec=VERSION_BCD(1,1,1),.TotalReportDescriptors=1,.HIDReportType=HID_DTYPE_Report,.HIDReportLength=sizeof(KeyboardReport)},
 .KeyboardEndpoint={.Header={sizeof(USB_Descriptor_Endpoint_t),DTYPE_Endpoint},
  .EndpointAddress=KEYBOARD_EPADDR,.Attributes=EP_TYPE_INTERRUPT,.EndpointSize=KEYBOARD_EPSIZE,.PollingIntervalMS=5},
 .ConsumerInterface={.Header={sizeof(USB_Descriptor_Interface_t),DTYPE_Interface},
  .InterfaceNumber=1,.TotalEndpoints=1,.Class=HID_CSCP_HIDClass},
 .ConsumerHID={.Header={sizeof(USB_HID_Descriptor_HID_t),HID_DTYPE_HID},
  .HIDSpec=VERSION_BCD(1,1,1),.TotalReportDescriptors=1,.HIDReportType=HID_DTYPE_Report,.HIDReportLength=sizeof(ConsumerReport)},
 .ConsumerEndpoint={.Header={sizeof(USB_Descriptor_Endpoint_t),DTYPE_Endpoint},
  .EndpointAddress=CONSUMER_EPADDR,.Attributes=EP_TYPE_INTERRUPT,.EndpointSize=CONSUMER_EPSIZE,.PollingIntervalMS=5}
};
static const USB_Descriptor_String_t PROGMEM Language = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
static const USB_Descriptor_String_t PROGMEM Manufacturer = USB_STRING_DESCRIPTOR(L"Macro Six Project");
static const USB_Descriptor_String_t PROGMEM Product = USB_STRING_DESCRIPTOR(L"Macro Six USB-C");
uint16_t CALLBACK_USB_GetDescriptor(uint16_t wValue,uint16_t wIndex,const void **DescriptorAddress) {
 const void *address=NULL; uint16_t size=NO_DESCRIPTOR;
 switch(wValue>>8) {
 case DTYPE_Device: address=&Device;size=sizeof(Device);break;
 case DTYPE_Configuration:address=&Config;size=sizeof(Config);break;
 case DTYPE_String:
  switch(wValue&0xff) {
  case 0:address=&Language;size=pgm_read_byte(&Language.Header.Size);break;
  case 1:address=&Manufacturer;size=pgm_read_byte(&Manufacturer.Header.Size);break;
  case 2:address=∏size=pgm_read_byte(&Product.Header.Size);break;
  } break;
 case HID_DTYPE_HID:
  if(wIndex==0) {address=&Config.KeyboardHID;size=sizeof(Config.KeyboardHID);}
  else if(wIndex==1) {address=&Config.ConsumerHID;size=sizeof(Config.ConsumerHID);}
  break;
 case HID_DTYPE_Report:
  if(wIndex==0) {address=KeyboardReport;size=sizeof(KeyboardReport);}
  else if(wIndex==1) {address=ConsumerReport;size=sizeof(ConsumerReport);}
  break;
 }
 *DescriptorAddress=address;return size;
}