style(swan_r5): pre-commit whitespace style changes

This commit is contained in:
Matthew McGowan 2021-09-28 14:13:04 -07:00
parent 8a3fb7bd13
commit 295cc18190
28 changed files with 217 additions and 187 deletions

View File

@ -48,7 +48,7 @@ void initialize_discharge_pin(void) {
void board_init(void) { void board_init(void) {
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build) // enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
SET_BIT (DBGMCU-> CR, DBGMCU_CR_DBG_SLEEP); SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
// Set tick interrupt priority, default HAL value is intentionally invalid // Set tick interrupt priority, default HAL value is intentionally invalid
// Without this, USB does not function. // Without this, USB does not function.

View File

@ -71,4 +71,3 @@ CIRCUITPY_BLEIO = 0
CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_BUSDEVICE = 0
CIRCUITPY_KEYPAD = 1 CIRCUITPY_KEYPAD = 1
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0

View File

@ -15,6 +15,7 @@ def test_dac_analog(p_in, p_out):
pin_in.deinit() pin_in.deinit()
pin_out.deinit() pin_out.deinit()
def test_dac_digital(p_in, p_out): def test_dac_digital(p_in, p_out):
print(f"Running dac digital test with pin {p_in} as input and {p_out} as output") print(f"Running dac digital test with pin {p_in} as input and {p_out} as output")
pin_in = digitalio.DigitalInOut(p_in) pin_in = digitalio.DigitalInOut(p_in)
@ -27,6 +28,7 @@ def test_dac_digital(p_in, p_out):
pin_in.deinit() pin_in.deinit()
pin_out.deinit() pin_out.deinit()
def test_dual(pair1, pair2): def test_dual(pair1, pair2):
# verifies that the DACs can be set independently # verifies that the DACs can be set independently
print(f"Running pair test\n") print(f"Running pair test\n")
@ -36,7 +38,7 @@ def test_dual(pair1, pair2):
pin2_out = analogio.AnalogOut(pair2[1]) pin2_out = analogio.AnalogOut(pair2[1])
for v in range(0, 65536, 4096): for v in range(0, 65536, 4096):
v2 = 65535-v v2 = 65535 - v
pin1_out.value = v pin1_out.value = v
pin2_out.value = v2 pin2_out.value = v2
print(f"Pair1: Value {v} read as {pin1_in.value}") print(f"Pair1: Value {v} read as {pin1_in.value}")
@ -47,6 +49,7 @@ def test_dual(pair1, pair2):
pin2_in.deinit() pin2_in.deinit()
pin2_out.deinit() pin2_out.deinit()
def test_analog_hilo(p_in, p_out): def test_analog_hilo(p_in, p_out):
print(f"Running analog hilo test with pin {p_in} as input and {p_out} as output") print(f"Running analog hilo test with pin {p_in} as input and {p_out} as output")
pin_in = analogio.AnalogIn(p_in) pin_in = analogio.AnalogIn(p_in)
@ -60,12 +63,14 @@ def test_analog_hilo(p_in, p_out):
pin_in.deinit() pin_in.deinit()
pin_out.deinit() pin_out.deinit()
def test_pair(pair): def test_pair(pair):
# FIXME: test_analog_hilo works fine alone, but fails when the other dac functions are executed # FIXME: test_analog_hilo works fine alone, but fails when the other dac functions are executed
test_analog_hilo(*pair) test_analog_hilo(*pair)
test_dac_analog(*pair) test_dac_analog(*pair)
test_dac_digital(*pair) test_dac_digital(*pair)
def main(): def main():
pair1 = (board.A3, board.DAC1) pair1 = (board.A3, board.DAC1)
pair2 = (board.A2, board.DAC2) pair2 = (board.A2, board.DAC2)
@ -78,4 +83,3 @@ def main():
main() main()

View File

@ -84,15 +84,17 @@ def _toggle_wait(pin_gpios):
answer = input() answer = input()
if bool(answer == "y"): if bool(answer == "y"):
done = True done = True
elif (bool(answer == "n")): elif bool(answer == "n"):
failed += pin failed += pin
done = True done = True
return failed return failed
def buildPin(pin): def buildPin(pin):
gpio = digitalio.DigitalInOut(pin) gpio = digitalio.DigitalInOut(pin)
return gpio return gpio
def run_test(pins): def run_test(pins):
""" """
@ -142,4 +144,5 @@ def run_test(pins):
print("No GPIO pins found") print("No GPIO pins found")
return NA, [] return NA, []
run_test([p for p in dir(board)]) run_test([p for p in dir(board)])

View File

@ -2,20 +2,21 @@ import board
import digitalio import digitalio
import time import time
def monitor_button(pin, callback): def monitor_button(pin, callback):
with digitalio.DigitalInOut(pin) as button: with digitalio.DigitalInOut(pin) as button:
newstate = not button.value # state is inverted newstate = not button.value # state is inverted
state = not newstate # ensure change reported to start with state = not newstate # ensure change reported to start with
while callback(newstate, newstate!=state): while callback(newstate, newstate != state):
state = newstate state = newstate
newstate = button.value newstate = button.value
time.sleep(0.01) time.sleep(0.01)
def print_changes(state, changed): def print_changes(state, changed):
if changed: if changed:
print(f"button pressed {state}") print(f"button pressed {state}")
return True return True
monitor_button(board.BUTTON_USR, print_changes) monitor_button(board.BUTTON_USR, print_changes)

View File

@ -15,4 +15,3 @@ def fade(pin):
else: else:
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down
time.sleep(0.01) time.sleep(0.01)

View File

@ -1,4 +1,3 @@
import board import board
import busio import busio
import digitalio import digitalio
@ -14,6 +13,7 @@ SPI_HERZ = 0x500000
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI) spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
def readByte(addr): def readByte(addr):
value = -1 value = -1
while not spi.try_lock(): while not spi.try_lock():
@ -32,6 +32,7 @@ def readByte(addr):
spi.unlock() spi.unlock()
cs.value = True cs.value = True
def writeByte(addr, value): def writeByte(addr, value):
while not spi.try_lock(): while not spi.try_lock():
pass pass
@ -46,9 +47,10 @@ def writeByte(addr, value):
finally: finally:
spi.unlock() spi.unlock()
# put the device in the correct mode to read the ID # put the device in the correct mode to read the ID
reg = readByte(BME680_SPI_REGISTER) reg = readByte(BME680_SPI_REGISTER)
if (reg & 16)!=0: if (reg & 16) != 0:
writeByte(BME680_SPI_REGISTER, reg & ~16) writeByte(BME680_SPI_REGISTER, reg & ~16)
id = readByte(BME680_CHIPID_REGISTER) id = readByte(BME680_CHIPID_REGISTER)

View File

@ -25,13 +25,13 @@ while True:
led.value = True led.value = True
# convert bytearray to string # convert bytearray to string
data_string = '*'.join([chr(b) for b in data]) data_string = "*".join([chr(b) for b in data])
print(data_string, end="") print(data_string, end="")
led.value = False led.value = False
if usb_cdc.console.in_waiting: if usb_cdc.console.in_waiting:
data = usb_cdc.console.read() data = usb_cdc.console.read()
data_string = '*'.join([chr(b) for b in data]) data_string = "*".join([chr(b) for b in data])
print("writing "+data_string) print("writing " + data_string)
uart.write(data) uart.write(data)

View File

@ -1,9 +1,10 @@
import os import os
def main(): def main():
print("Random number test") print("Random number test")
r = os.urandom(32) r = os.urandom(32)
print(f"urandom TRNG string is {r}") print(f"urandom TRNG string is {r}")
main()
main()

View File

@ -36,7 +36,7 @@
#define STM_BKPSRAM_SIZE 0 #define STM_BKPSRAM_SIZE 0
#define STM_BKPSRAM_START 0 #define STM_BKPSRAM_START 0
#define HAL_PWREx_EnableBkUpReg() #define HAL_PWREx_EnableBkUpReg()
// backup RAM disabled for now. Will have the backup region at the top of SRAM3 which is retained. // backup RAM disabled for now. Will have the backup region at the top of SRAM3 which is retained.
#else #else
#define STM_BKPSRAM_SIZE 0x1000 #define STM_BKPSRAM_SIZE 0x1000
#define STM_BKPSRAM_START BKPSRAM_BASE #define STM_BKPSRAM_START BKPSRAM_BASE

View File

@ -84,32 +84,52 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
} }
uint32_t adc_channel(uint32_t channel) { uint32_t adc_channel(uint32_t channel) {
#if CPY_STM32L4 #if CPY_STM32L4
switch (channel) { switch (channel) {
case 0: return ADC_CHANNEL_0; case 0:
case 1: return ADC_CHANNEL_1; return ADC_CHANNEL_0;
case 2: return ADC_CHANNEL_2; case 1:
case 3: return ADC_CHANNEL_3; return ADC_CHANNEL_1;
case 4: return ADC_CHANNEL_4; case 2:
case 5: return ADC_CHANNEL_5; return ADC_CHANNEL_2;
case 6: return ADC_CHANNEL_6; case 3:
case 7: return ADC_CHANNEL_7; return ADC_CHANNEL_3;
case 8: return ADC_CHANNEL_8; case 4:
case 9: return ADC_CHANNEL_9; return ADC_CHANNEL_4;
case 10: return ADC_CHANNEL_10; case 5:
case 11: return ADC_CHANNEL_11; return ADC_CHANNEL_5;
case 12: return ADC_CHANNEL_12; case 6:
case 13: return ADC_CHANNEL_13; return ADC_CHANNEL_6;
case 14: return ADC_CHANNEL_14; case 7:
case 15: return ADC_CHANNEL_15; return ADC_CHANNEL_7;
case 16: return ADC_CHANNEL_16; case 8:
case 17: return ADC_CHANNEL_17; return ADC_CHANNEL_8;
case 18: return ADC_CHANNEL_18; case 9:
default: return 0; return ADC_CHANNEL_9;
case 10:
return ADC_CHANNEL_10;
case 11:
return ADC_CHANNEL_11;
case 12:
return ADC_CHANNEL_12;
case 13:
return ADC_CHANNEL_13;
case 14:
return ADC_CHANNEL_14;
case 15:
return ADC_CHANNEL_15;
case 16:
return ADC_CHANNEL_16;
case 17:
return ADC_CHANNEL_17;
case 18:
return ADC_CHANNEL_18;
default:
return 0;
} }
#else #else
return channel; return channel;
#endif #endif
} }
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
@ -151,23 +171,25 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
AdcHandle.Init.NbrOfConversion = 1; AdcHandle.Init.NbrOfConversion = 1;
AdcHandle.Init.DMAContinuousRequests = DISABLE; AdcHandle.Init.DMAContinuousRequests = DISABLE;
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
#ifdef ADC_OVR_DATA_OVERWRITTEN #ifdef ADC_OVR_DATA_OVERWRITTEN
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */ AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
#endif #endif
if (HAL_ADC_Init(&AdcHandle)!=HAL_OK) return 0; if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
return 0;
}
sConfig.Channel = adc_channel(self->pin->adc_channel); // ADC_CHANNEL_0 <-normal iteration, not mask sConfig.Channel = adc_channel(self->pin->adc_channel); // ADC_CHANNEL_0 <-normal iteration, not mask
sConfig.Rank = 1; sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME; sConfig.SamplingTime = ADC_SAMPLETIME;
#if CPY_STM32L4 #if CPY_STM32L4
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */ sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */ sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
if (!IS_ADC_CHANNEL(&AdcHandle, sConfig.Channel)) { if (!IS_ADC_CHANNEL(&AdcHandle, sConfig.Channel)) {
return 0; return 0;
} }
#endif #endif
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig)!=HAL_OK) { if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) {
return 0; return 0;
} }
#if CPY_STM32L4 #if CPY_STM32L4
@ -175,7 +197,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
return 0; return 0;
} }
#endif #endif
if (HAL_ADC_Start(&AdcHandle)!=HAL_OK) { if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {
return 0; return 0;
} }
HAL_ADC_PollForConversion(&AdcHandle,1); HAL_ADC_PollForConversion(&AdcHandle,1);

View File

@ -42,12 +42,12 @@
#endif #endif
void Error_Handler(void) { void Error_Handler(void) {
for(;;) { for (;;) {
} }
} }
#define HAL_CHECK(x) if (x!=HAL_OK) Error_Handler() #define HAL_CHECK(x) if (x != HAL_OK) Error_Handler()
void stm32_peripherals_clocks_init(void) { void stm32_peripherals_clocks_init(void) {

View File

@ -38,8 +38,8 @@ void stm32_peripherals_gpio_init(void) {
__HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE();
// These ports are not used on the Swan R5 but may need to be enabeld on other boards // These ports are not used on the Swan R5 but may need to be enabeld on other boards
//__HAL_RCC_GPIOH_CLK_ENABLE(); // __HAL_RCC_GPIOH_CLK_ENABLE();
//__HAL_RCC_GPIOI_CLK_ENABLE(); // __HAL_RCC_GPIOI_CLK_ENABLE();
// Never reset pins // Never reset pins
never_reset_pin_number(2,14); // PC14 OSC32_IN never_reset_pin_number(2,14); // PC14 OSC32_IN

View File

@ -167,7 +167,7 @@ const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = {
// Timers // Timers
// TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins // TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, /*TIM9*/NULL, NULL, NULL, NULL, NULL, NULL, TIM15, TIM16, TIM17}; TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, /*TIM9*/ NULL, NULL, NULL, NULL, NULL, NULL, TIM15, TIM16, TIM17};
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = { const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
TIM(2, 1, 1, &pin_PA00), TIM(2, 1, 1, &pin_PA00),
@ -184,7 +184,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
TIM(3, 2, 1, &pin_PA06), TIM(3, 2, 1, &pin_PA06),
TIM(16, 15, 1, &pin_PA06), TIM(16, 15, 1, &pin_PA06),
TIM(3, 2, 2, &pin_PA07), TIM(3, 2, 2, &pin_PA07),
//TIM(17, 15, 1, &pin_PA07), // peripheral indices are 1 based, stored 0-based with 4 bits available. // TIM(17, 15, 1, &pin_PA07), // peripheral indices are 1 based, stored 0-based with 4 bits available.
TIM(1, 1, 1, &pin_PA08), TIM(1, 1, 1, &pin_PA08),
TIM(1, 1, 2, &pin_PA09), TIM(1, 1, 2, &pin_PA09),
TIM(1, 1, 3, &pin_PA10), TIM(1, 1, 3, &pin_PA10),
@ -200,7 +200,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
TIM(4, 2, 3, &pin_PB08), TIM(4, 2, 3, &pin_PB08),
TIM(16, 15, 1, &pin_PB08), TIM(16, 15, 1, &pin_PB08),
TIM(4, 2, 4, &pin_PB09), TIM(4, 2, 4, &pin_PB09),
//TIM(17, 15, 1, &pin_PB09), // peripheral indices are 1 based, stored 0-based with 4 bits available. // TIM(17, 15, 1, &pin_PB09), // peripheral indices are 1 based, stored 0-based with 4 bits available.
TIM(2, 1, 3, &pin_PB10), TIM(2, 1, 3, &pin_PB10),
TIM(2, 1, 4, &pin_PB11), TIM(2, 1, 4, &pin_PB11),
TIM(15, 15, 1, &pin_PB14), TIM(15, 15, 1, &pin_PB14),
@ -218,7 +218,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
TIM(4, 2, 3, &pin_PD14), TIM(4, 2, 3, &pin_PD14),
TIM(4, 2, 4, &pin_PD15), TIM(4, 2, 4, &pin_PD15),
TIM(16, 15, 1, &pin_PE00), TIM(16, 15, 1, &pin_PE00),
//TIM(17, 15, 1, &pin_PE01), // peripheral indices are 1 based, stored 0-based with 4 bits available. // TIM(17, 15, 1, &pin_PE01), // peripheral indices are 1 based, stored 0-based with 4 bits available.
TIM(3, 2, 1, &pin_PE03), TIM(3, 2, 1, &pin_PE03),
TIM(3, 2, 2, &pin_PE04), TIM(3, 2, 2, &pin_PE04),
TIM(3, 2, 3, &pin_PE05), TIM(3, 2, 3, &pin_PE05),

View File

@ -57,7 +57,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN];
// Timers // Timers
#define TIM_BANK_ARRAY_LEN 17 #define TIM_BANK_ARRAY_LEN 17
#define TIM_PIN_ARRAY_LEN (73-3) #define TIM_PIN_ARRAY_LEN (73 - 3)
extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN]; extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN];
extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];

View File

@ -138,9 +138,9 @@ STATIC uint32_t get_bank(uint32_t addr) {
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
if (addr >= flash_layout[0].base_address) { if (addr >= flash_layout[0].base_address) {
uint32_t sector_index = 0; uint32_t sector_index = 0;
if (MP_ARRAY_SIZE(flash_layout)==1) { if (MP_ARRAY_SIZE(flash_layout) == 1) {
sector_index = (addr-flash_layout[0].base_address)/flash_layout[0].sector_size; sector_index = (addr - flash_layout[0].base_address) / flash_layout[0].sector_size;
if (sector_index>=flash_layout[0].sector_count) { if (sector_index >= flash_layout[0].sector_count) {
return 0; return 0;
} }
if (start_addr) { if (start_addr) {
@ -193,7 +193,7 @@ void port_internal_flash_flush(void) {
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2); __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2);
#else #else
#ifndef FLASH_FLAG_ALL_ERRORS #ifndef FLASH_FLAG_ALL_ERRORS
#define FLASH_FLAG_ALL_ERRORS FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGPERR |FLASH_FLAG_PGSERR #define FLASH_FLAG_ALL_ERRORS FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR
#endif #endif
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
#endif #endif
@ -256,7 +256,7 @@ void port_internal_flash_flush(void) {
// program the flash word by word // program the flash word by word
for (uint32_t i = 0; i < sector_size / 8; i++) { for (uint32_t i = 0; i < sector_size / 8; i++) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, sector_start_addr, if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, sector_start_addr,
*(uint64_t*)cache_addr) != HAL_OK) { *(uint64_t *)cache_addr) != HAL_OK) {
// error occurred during flash write // error occurred during flash write
HAL_FLASH_Lock(); // lock the flash HAL_FLASH_Lock(); // lock the flash
reset_into_safe_mode(FLASH_WRITE_FAIL); reset_into_safe_mode(FLASH_WRITE_FAIL);

View File

@ -285,8 +285,7 @@ uint8_t const desc_bos[] =
TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT)
}; };
uint8_t const * tud_descriptor_bos_cb(void) uint8_t const *tud_descriptor_bos_cb(void) {
{
return desc_bos; return desc_bos;
} }
@ -299,22 +298,22 @@ const uint8_t ms_os_20_descriptor_template[] =
U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
// 8 Configuration subset header: length, type, configuration index, reserved, configuration total length // 8 Configuration subset header: length, type, configuration index, reserved, configuration total length
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A), U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A),
// 8 Function Subset header: length, type, first interface, reserved, subset length // 8 Function Subset header: length, type, first interface, reserved, subset length
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), /* 22 */MS_OS_20_ITF_NUM_MAGIC, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08), U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), /* 22 */ MS_OS_20_ITF_NUM_MAGIC, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08),
// 20 MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID // 20 MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
// MS OS 2.0 Registry property descriptor: length, type // MS OS 2.0 Registry property descriptor: length, type
U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
U16_TO_U8S_LE(0x0050), // wPropertyDataLength U16_TO_U8S_LE(0x0050), // wPropertyDataLength
//bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”. // bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
'{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, '{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00,
'0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00,
'8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00,
@ -343,11 +342,11 @@ static const uint8_t usb_vendor_descriptor_template[] = {
0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: number] 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: number]
#define VENDOR_OUT_ENDPOINT_INDEX 11 #define VENDOR_OUT_ENDPOINT_INDEX 11
0x02, // 12 bmAttributes (Bulk) 0x02, // 12 bmAttributes (Bulk)
#if USB_HIGHSPEED #if USB_HIGHSPEED
0x00, 0x02, // 13,14 wMaxPacketSize 512 0x00, 0x02, // 13,14 wMaxPacketSize 512
#else #else
0x40, 0x00, // 13,14 wMaxPacketSize 64 0x40, 0x00, // 13,14 wMaxPacketSize 64
#endif #endif
0x0, // 15 bInterval 0 0x0, // 15 bInterval 0
// Vendor IN Endpoint Descriptor // Vendor IN Endpoint Descriptor
@ -376,14 +375,14 @@ static supervisor_allocation *ms_os_20_descriptor_allocation;
size_t vendor_ms_os_20_descriptor_length() { size_t vendor_ms_os_20_descriptor_length() {
return sizeof(ms_os_20_descriptor_template); return sizeof(ms_os_20_descriptor_template);
} }
uint8_t const* vendor_ms_os_20_descriptor() { uint8_t const *vendor_ms_os_20_descriptor() {
return (uint8_t *)ms_os_20_descriptor_allocation->ptr; return (uint8_t *)ms_os_20_descriptor_allocation->ptr;
} }
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string) { size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string) {
if (ms_os_20_descriptor_template[MS_OS_20_ITF_NUM_OFFSET]==MS_OS_20_ITF_NUM_MAGIC) { if (ms_os_20_descriptor_template[MS_OS_20_ITF_NUM_OFFSET] == MS_OS_20_ITF_NUM_MAGIC) {
ms_os_20_descriptor_allocation = ms_os_20_descriptor_allocation =
allocate_memory(align32_size(sizeof(ms_os_20_descriptor_template)), allocate_memory(align32_size(sizeof(ms_os_20_descriptor_template)),
/*high_address*/ false, /*movable*/ false); /*high_address*/ false, /*movable*/ false);

View File

@ -45,7 +45,7 @@ size_t usb_vendor_descriptor_length(void);
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string); size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string);
size_t vendor_ms_os_20_descriptor_length(void); size_t vendor_ms_os_20_descriptor_length(void);
uint8_t const* vendor_ms_os_20_descriptor(void); uint8_t const *vendor_ms_os_20_descriptor(void);
#endif #endif
#endif /* SHARED_MODULE_USB_CDC___INIT___H */ #endif /* SHARED_MODULE_USB_CDC___INIT___H */

View File

@ -34,6 +34,6 @@ enum
}; };
size_t vendor_ms_os_20_descriptor_length(void); size_t vendor_ms_os_20_descriptor_length(void);
uint8_t const* vendor_ms_os_20_descriptor(void); uint8_t const *vendor_ms_os_20_descriptor(void);
#endif /* USB_DESCRIPTORS_H_ */ #endif /* USB_DESCRIPTORS_H_ */