|
| 1 | +/** |
| 2 | + * @file microbit.c |
| 3 | + * @brief board ID for the BBC Microbit board |
| 4 | + * |
| 5 | + * DAPLink Interface Firmware |
| 6 | + * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved |
| 7 | + * SPDX-License-Identifier: Apache-2.0 |
| 8 | + * |
| 9 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | + * not use this file except in compliance with the License. |
| 11 | + * You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | + * See the License for the specific language governing permissions and |
| 19 | + * limitations under the License. |
| 20 | + */ |
| 21 | +#include "fsl_device_registers.h" |
| 22 | +#include "IO_Config.h" |
| 23 | +#include "DAP.h" |
| 24 | +#include "target_family.h" |
| 25 | +#include "target_board.h" |
| 26 | + |
| 27 | +const char * const board_id_mb_1_3 = "9900"; |
| 28 | +const char * const board_id_mb_1_5 = "9901"; |
| 29 | + |
| 30 | +typedef enum { |
| 31 | + BOARD_VERSION_1_3 = 0, |
| 32 | + BOARD_VERSION_1_5 = 1, |
| 33 | +} mb_version_t; |
| 34 | + |
| 35 | +// Enables Board Type Pin, reads it and disables it |
| 36 | +// Depends on gpio_init() to have been executed already |
| 37 | +static uint8_t read_board_type_pin(void) { |
| 38 | + uint8_t pin_state = 0; |
| 39 | + // GPIO mode, Pull enable, pull down, input |
| 40 | + PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(1) | PORT_PCR_PE(1) | PORT_PCR_PS(0); |
| 41 | + PIN_BOARD_TYPE_GPIO->PDDR &= ~PIN_BOARD_TYPE; |
| 42 | + // Wait to stabilise, based on gpio.c busy_wait(), at -O2 10000 iterations delay ~850us |
| 43 | + for (volatile uint32_t i = 10000; i > 0; i--); |
| 44 | + // Read pin |
| 45 | + pin_state = (PIN_BOARD_TYPE_GPIO->PDIR & PIN_BOARD_TYPE); |
| 46 | + // Revert and disable |
| 47 | + PIN_BOARD_TYPE_PORT->PCR[PIN_BOARD_TYPE_BIT] = PORT_PCR_MUX(0) | PORT_PCR_PE(0); |
| 48 | + return pin_state; |
| 49 | +} |
| 50 | + |
| 51 | +static void set_board_id(mb_version_t board_version) { |
| 52 | + switch (board_version) { |
| 53 | + case BOARD_VERSION_1_3: |
| 54 | + target_device.rt_board_id = board_id_mb_1_3; |
| 55 | + break; |
| 56 | + case BOARD_VERSION_1_5: |
| 57 | + target_device.rt_board_id = board_id_mb_1_5; |
| 58 | + break; |
| 59 | + default: |
| 60 | + target_device.rt_board_id = board_id_mb_1_5; |
| 61 | + break; |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// Called in main_task() to init before USB and files are configured |
| 66 | +static void prerun_board_config(void) { |
| 67 | + // With only two boards the digital pin read maps directly to the type |
| 68 | + mb_version_t board_version = (mb_version_t)read_board_type_pin(); |
| 69 | + set_board_id(board_version); |
| 70 | +} |
| 71 | + |
| 72 | +// USB HID override function return 1 if the activity is trivial or response is null |
| 73 | +uint8_t usbd_hid_no_activity(uint8_t *buf) |
| 74 | +{ |
| 75 | + if(buf[0] == ID_DAP_Vendor3 && buf[1] == 0) |
| 76 | + return 1; |
| 77 | + else |
| 78 | + return 0; |
| 79 | +} |
| 80 | + |
| 81 | +const board_info_t g_board_info = { |
| 82 | + .info_version = kBoardInfoVersion, |
| 83 | + .family_id = kNordic_Nrf51_FamilyID, |
| 84 | + .daplink_url_name = "MICROBITHTM", |
| 85 | + .daplink_drive_name = "MICROBIT ", |
| 86 | + .daplink_target_url = "https://microbit.org/device/?id=@B&v=@V", |
| 87 | + .prerun_board_config = prerun_board_config, |
| 88 | + .target_cfg = &target_device, |
| 89 | +}; |
0 commit comments