Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /*
MrBedfordVan 0:b9164b348919 2 The MIT License (MIT)
MrBedfordVan 0:b9164b348919 3
MrBedfordVan 0:b9164b348919 4 Copyright (c) 2016 British Broadcasting Corporation.
MrBedfordVan 0:b9164b348919 5 This software is provided by Lancaster University by arrangement with the BBC.
MrBedfordVan 0:b9164b348919 6
MrBedfordVan 0:b9164b348919 7 Permission is hereby granted, free of charge, to any person obtaining a
MrBedfordVan 0:b9164b348919 8 copy of this software and associated documentation files (the "Software"),
MrBedfordVan 0:b9164b348919 9 to deal in the Software without restriction, including without limitation
MrBedfordVan 0:b9164b348919 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
MrBedfordVan 0:b9164b348919 11 and/or sell copies of the Software, and to permit persons to whom the
MrBedfordVan 0:b9164b348919 12 Software is furnished to do so, subject to the following conditions:
MrBedfordVan 0:b9164b348919 13
MrBedfordVan 0:b9164b348919 14 The above copyright notice and this permission notice shall be included in
MrBedfordVan 0:b9164b348919 15 all copies or substantial portions of the Software.
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MrBedfordVan 0:b9164b348919 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MrBedfordVan 0:b9164b348919 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
MrBedfordVan 0:b9164b348919 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MrBedfordVan 0:b9164b348919 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
MrBedfordVan 0:b9164b348919 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
MrBedfordVan 0:b9164b348919 23 DEALINGS IN THE SOFTWARE.
MrBedfordVan 0:b9164b348919 24 */
MrBedfordVan 0:b9164b348919 25
MrBedfordVan 0:b9164b348919 26 /**
MrBedfordVan 0:b9164b348919 27 * Definition of the LED Matrix maps supported.
MrBedfordVan 0:b9164b348919 28 * Each map represents the layou of a different device.
MrBedfordVan 0:b9164b348919 29 *
MrBedfordVan 0:b9164b348919 30 * Ensure only one of these is selected.
MrBedfordVan 0:b9164b348919 31 */
MrBedfordVan 0:b9164b348919 32
MrBedfordVan 0:b9164b348919 33 #ifndef MICROBIT_MATRIX_MAPS_H
MrBedfordVan 0:b9164b348919 34 #define MICROBIT_MATRIX_MAPS_H
MrBedfordVan 0:b9164b348919 35
MrBedfordVan 0:b9164b348919 36 #include "MicroBitConfig.h"
MrBedfordVan 0:b9164b348919 37 #include "mbed.h"
MrBedfordVan 0:b9164b348919 38
MrBedfordVan 0:b9164b348919 39 #define NO_CONN 0
MrBedfordVan 0:b9164b348919 40
MrBedfordVan 0:b9164b348919 41 /**
MrBedfordVan 0:b9164b348919 42 * Provides the mapping from Matrix ROW/COL to a linear X/Y buffer.
MrBedfordVan 0:b9164b348919 43 * It's arranged such that matrixMap[col, row] provides the [x,y] screen co-ord.
MrBedfordVan 0:b9164b348919 44 */
MrBedfordVan 0:b9164b348919 45
MrBedfordVan 0:b9164b348919 46 struct MatrixPoint
MrBedfordVan 0:b9164b348919 47 {
MrBedfordVan 0:b9164b348919 48 uint8_t x;
MrBedfordVan 0:b9164b348919 49 uint8_t y;
MrBedfordVan 0:b9164b348919 50 };
MrBedfordVan 0:b9164b348919 51
MrBedfordVan 0:b9164b348919 52 /**
MrBedfordVan 0:b9164b348919 53 * This struct presumes rows and columns are arranged contiguously...
MrBedfordVan 0:b9164b348919 54 */
MrBedfordVan 0:b9164b348919 55 struct MatrixMap
MrBedfordVan 0:b9164b348919 56 {
MrBedfordVan 0:b9164b348919 57 int width; // The physical width of the LED matrix, in pixels.
MrBedfordVan 0:b9164b348919 58 int height; // The physical height of the LED matrix, in pixels.
MrBedfordVan 0:b9164b348919 59 int rows; // The number of drive pins connected to LEDs.
MrBedfordVan 0:b9164b348919 60 int columns; // The number of sink pins connected to the LEDs.
MrBedfordVan 0:b9164b348919 61
MrBedfordVan 0:b9164b348919 62 PinName rowStart; // ID of the first drive pin.
MrBedfordVan 0:b9164b348919 63 PinName columnStart; // ID of the first sink pink.
MrBedfordVan 0:b9164b348919 64
MrBedfordVan 0:b9164b348919 65 const MatrixPoint *map; // Table mapping logical LED positions to physical positions.
MrBedfordVan 0:b9164b348919 66 };
MrBedfordVan 0:b9164b348919 67
MrBedfordVan 0:b9164b348919 68 /*
MrBedfordVan 0:b9164b348919 69 * Dimensions for well known micro:bit LED configurations
MrBedfordVan 0:b9164b348919 70 */
MrBedfordVan 0:b9164b348919 71 #define MICROBIT_DISPLAY_WIDTH 5
MrBedfordVan 0:b9164b348919 72 #define MICROBIT_DISPLAY_HEIGHT 5
MrBedfordVan 0:b9164b348919 73 #define MICROBIT_DISPLAY_ROW1 p13
MrBedfordVan 0:b9164b348919 74 #define MICROBIT_DISPLAY_COL1 p4
MrBedfordVan 0:b9164b348919 75
MrBedfordVan 0:b9164b348919 76
MrBedfordVan 0:b9164b348919 77 #if MICROBIT_DISPLAY_TYPE == MICROBUG_REFERENCE_DEVICE
MrBedfordVan 0:b9164b348919 78
MrBedfordVan 0:b9164b348919 79 #define MICROBIT_DISPLAY_COLUMN_COUNT 5
MrBedfordVan 0:b9164b348919 80 #define MICROBIT_DISPLAY_ROW_COUNT 5
MrBedfordVan 0:b9164b348919 81
MrBedfordVan 0:b9164b348919 82 const MatrixPoint microbitDisplayMap[MICROBIT_DISPLAY_ROW_COUNT * MICROBIT_DISPLAY_COLUMN_COUNT] =
MrBedfordVan 0:b9164b348919 83 {
MrBedfordVan 0:b9164b348919 84 {0,0},{0,1},{0,2},{0,3},{0,4},
MrBedfordVan 0:b9164b348919 85 {1,0},{1,1},{1,2},{1,3},{1,4},
MrBedfordVan 0:b9164b348919 86 {2,0},{2,1},{2,2},{2,3},{2,4},
MrBedfordVan 0:b9164b348919 87 {3,0},{3,1},{3,2},{3,3},{3,4},
MrBedfordVan 0:b9164b348919 88 {4,0},{4,1},{4,2},{4,3},{4,4}
MrBedfordVan 0:b9164b348919 89 };
MrBedfordVan 0:b9164b348919 90
MrBedfordVan 0:b9164b348919 91 #endif
MrBedfordVan 0:b9164b348919 92
MrBedfordVan 0:b9164b348919 93 #if MICROBIT_DISPLAY_TYPE == MICROBIT_3X9
MrBedfordVan 0:b9164b348919 94
MrBedfordVan 0:b9164b348919 95 #define MICROBIT_DISPLAY_COLUMN_COUNT 9
MrBedfordVan 0:b9164b348919 96 #define MICROBIT_DISPLAY_ROW_COUNT 3
MrBedfordVan 0:b9164b348919 97
MrBedfordVan 0:b9164b348919 98 const MatrixPoint microbitDisplayMap[MICROBIT_DISPLAY_ROW_COUNT * MICROBIT_DISPLAY_COLUMN_COUNT] =
MrBedfordVan 0:b9164b348919 99 {
MrBedfordVan 0:b9164b348919 100 {0,4},{0,3},{1,1},
MrBedfordVan 0:b9164b348919 101 {1,4},{4,2},{0,1},
MrBedfordVan 0:b9164b348919 102 {2,4},{3,2},{4,0},
MrBedfordVan 0:b9164b348919 103 {3,4},{2,2},{3,0},
MrBedfordVan 0:b9164b348919 104 {4,4},{1,2},{2,0},
MrBedfordVan 0:b9164b348919 105 {4,3},{0,2},{1,0},
MrBedfordVan 0:b9164b348919 106 {3,3},{4,1},{0,0},
MrBedfordVan 0:b9164b348919 107 {2,3},{3,1},{NO_CONN,NO_CONN},
MrBedfordVan 0:b9164b348919 108 {1,3},{2,1},{NO_CONN,NO_CONN}
MrBedfordVan 0:b9164b348919 109 };
MrBedfordVan 0:b9164b348919 110
MrBedfordVan 0:b9164b348919 111 #endif
MrBedfordVan 0:b9164b348919 112
MrBedfordVan 0:b9164b348919 113 #if MICROBIT_DISPLAY_TYPE == MICROBIT_SB1
MrBedfordVan 0:b9164b348919 114
MrBedfordVan 0:b9164b348919 115 #define MICROBIT_DISPLAY_COLUMN_COUNT 3
MrBedfordVan 0:b9164b348919 116 #define MICROBIT_DISPLAY_ROW_COUNT 9
MrBedfordVan 0:b9164b348919 117
MrBedfordVan 0:b9164b348919 118 const MatrixPoint microbitDisplayMap[MICROBIT_DISPLAY_ROW_COUNT * MICROBIT_DISPLAY_COLUMN_COUNT] =
MrBedfordVan 0:b9164b348919 119 {
MrBedfordVan 0:b9164b348919 120 {0,4},{1,4},{2,4},{3,4},{4,4},{4,3},{3,3},{2,3},{1,3},
MrBedfordVan 0:b9164b348919 121 {0,3},{4,2},{3,2},{2,2},{1,2},{0,2},{4,1},{3,1},{2,1},
MrBedfordVan 0:b9164b348919 122 {1,1},{0,1},{4,0},{3,0},{2,0},{1,0},{0,0},{NO_CONN,NO_CONN},{NO_CONN,NO_CONN}
MrBedfordVan 0:b9164b348919 123 };
MrBedfordVan 0:b9164b348919 124
MrBedfordVan 0:b9164b348919 125 #endif
MrBedfordVan 0:b9164b348919 126
MrBedfordVan 0:b9164b348919 127 #if MICROBIT_DISPLAY_TYPE == MICROBIT_SB2
MrBedfordVan 0:b9164b348919 128
MrBedfordVan 0:b9164b348919 129 #define MICROBIT_DISPLAY_COLUMN_COUNT 9
MrBedfordVan 0:b9164b348919 130 #define MICROBIT_DISPLAY_ROW_COUNT 3
MrBedfordVan 0:b9164b348919 131
MrBedfordVan 0:b9164b348919 132 const MatrixPoint microbitDisplayMap[MICROBIT_DISPLAY_ROW_COUNT * MICROBIT_DISPLAY_COLUMN_COUNT] =
MrBedfordVan 0:b9164b348919 133 {
MrBedfordVan 0:b9164b348919 134 {0,0},{4,2},{2,4},
MrBedfordVan 0:b9164b348919 135 {2,0},{0,2},{4,4},
MrBedfordVan 0:b9164b348919 136 {4,0},{2,2},{0,4},
MrBedfordVan 0:b9164b348919 137 {4,3},{1,0},{0,1},
MrBedfordVan 0:b9164b348919 138 {3,3},{3,0},{1,1},
MrBedfordVan 0:b9164b348919 139 {2,3},{3,4},{2,1},
MrBedfordVan 0:b9164b348919 140 {1,3},{1,4},{3,1},
MrBedfordVan 0:b9164b348919 141 {0,3},{NO_CONN,NO_CONN},{4,1},
MrBedfordVan 0:b9164b348919 142 {1,2},{NO_CONN,NO_CONN},{3,2}
MrBedfordVan 0:b9164b348919 143 };
MrBedfordVan 0:b9164b348919 144
MrBedfordVan 0:b9164b348919 145 #endif
MrBedfordVan 0:b9164b348919 146
MrBedfordVan 0:b9164b348919 147 //ROW1 and COL1 are defined in mbed classic:
MrBedfordVan 0:b9164b348919 148 //https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/TARGET_NRF51_MICROBIT/PinNames.h
MrBedfordVan 0:b9164b348919 149 const MatrixMap microbitMatrixMap =
MrBedfordVan 0:b9164b348919 150 {
MrBedfordVan 0:b9164b348919 151 MICROBIT_DISPLAY_WIDTH,
MrBedfordVan 0:b9164b348919 152 MICROBIT_DISPLAY_HEIGHT,
MrBedfordVan 0:b9164b348919 153 MICROBIT_DISPLAY_ROW_COUNT,
MrBedfordVan 0:b9164b348919 154 MICROBIT_DISPLAY_COLUMN_COUNT,
MrBedfordVan 0:b9164b348919 155 MICROBIT_DISPLAY_ROW1,
MrBedfordVan 0:b9164b348919 156 MICROBIT_DISPLAY_COL1,
MrBedfordVan 0:b9164b348919 157 microbitDisplayMap
MrBedfordVan 0:b9164b348919 158 };
MrBedfordVan 0:b9164b348919 159
MrBedfordVan 0:b9164b348919 160 #endif