![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
センサー動作確認版
Dependencies: MPU9150_DMP QuaternionMath iSDIO mbed-rtos mbed
taskLed.cpp@0:65a0ae5578da, 2016-05-14 (annotated)
- Committer:
- yishii
- Date:
- Sat May 14 07:11:48 2016 +0000
- Revision:
- 0:65a0ae5578da
- Child:
- 1:73543a1fbe62
Supported to use with Nucleo F303K8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yishii | 0:65a0ae5578da | 1 | #include "mbed.h" |
yishii | 0:65a0ae5578da | 2 | #include "math.h" |
yishii | 0:65a0ae5578da | 3 | #include "rtos.h" |
yishii | 0:65a0ae5578da | 4 | #include "gpio_defs.h" |
yishii | 0:65a0ae5578da | 5 | #include "configure.h" |
yishii | 0:65a0ae5578da | 6 | |
yishii | 0:65a0ae5578da | 7 | |
yishii | 0:65a0ae5578da | 8 | // Clock 72MHz |
yishii | 0:65a0ae5578da | 9 | // 0.35us : NOP*25.2 |
yishii | 0:65a0ae5578da | 10 | // 0.8us : 57.6 |
yishii | 0:65a0ae5578da | 11 | // 0.7us : 50.4 |
yishii | 0:65a0ae5578da | 12 | // 0.6us : 43.2 |
yishii | 0:65a0ae5578da | 13 | |
yishii | 0:65a0ae5578da | 14 | inline void sleep0_35us(void) |
yishii | 0:65a0ae5578da | 15 | { |
yishii | 0:65a0ae5578da | 16 | asm("nop"); |
yishii | 0:65a0ae5578da | 17 | asm("nop"); |
yishii | 0:65a0ae5578da | 18 | asm("nop"); |
yishii | 0:65a0ae5578da | 19 | asm("nop"); |
yishii | 0:65a0ae5578da | 20 | asm("nop"); |
yishii | 0:65a0ae5578da | 21 | asm("nop"); |
yishii | 0:65a0ae5578da | 22 | asm("nop"); |
yishii | 0:65a0ae5578da | 23 | #if 0 |
yishii | 0:65a0ae5578da | 24 | asm("nop"); |
yishii | 0:65a0ae5578da | 25 | asm("nop"); |
yishii | 0:65a0ae5578da | 26 | asm("nop"); |
yishii | 0:65a0ae5578da | 27 | asm("nop"); |
yishii | 0:65a0ae5578da | 28 | asm("nop"); |
yishii | 0:65a0ae5578da | 29 | asm("nop"); |
yishii | 0:65a0ae5578da | 30 | asm("nop"); |
yishii | 0:65a0ae5578da | 31 | asm("nop"); |
yishii | 0:65a0ae5578da | 32 | asm("nop"); |
yishii | 0:65a0ae5578da | 33 | asm("nop"); |
yishii | 0:65a0ae5578da | 34 | asm("nop"); |
yishii | 0:65a0ae5578da | 35 | asm("nop"); |
yishii | 0:65a0ae5578da | 36 | asm("nop"); |
yishii | 0:65a0ae5578da | 37 | asm("nop"); |
yishii | 0:65a0ae5578da | 38 | asm("nop"); |
yishii | 0:65a0ae5578da | 39 | asm("nop"); |
yishii | 0:65a0ae5578da | 40 | asm("nop"); |
yishii | 0:65a0ae5578da | 41 | asm("nop"); |
yishii | 0:65a0ae5578da | 42 | #endif |
yishii | 0:65a0ae5578da | 43 | } |
yishii | 0:65a0ae5578da | 44 | inline void sleep0_8us(void) |
yishii | 0:65a0ae5578da | 45 | { |
yishii | 0:65a0ae5578da | 46 | asm("nop"); |
yishii | 0:65a0ae5578da | 47 | asm("nop"); |
yishii | 0:65a0ae5578da | 48 | asm("nop"); |
yishii | 0:65a0ae5578da | 49 | asm("nop"); |
yishii | 0:65a0ae5578da | 50 | asm("nop"); |
yishii | 0:65a0ae5578da | 51 | asm("nop"); |
yishii | 0:65a0ae5578da | 52 | asm("nop"); |
yishii | 0:65a0ae5578da | 53 | asm("nop"); |
yishii | 0:65a0ae5578da | 54 | asm("nop"); |
yishii | 0:65a0ae5578da | 55 | asm("nop"); |
yishii | 0:65a0ae5578da | 56 | asm("nop"); |
yishii | 0:65a0ae5578da | 57 | asm("nop"); |
yishii | 0:65a0ae5578da | 58 | asm("nop"); |
yishii | 0:65a0ae5578da | 59 | asm("nop"); |
yishii | 0:65a0ae5578da | 60 | asm("nop"); |
yishii | 0:65a0ae5578da | 61 | asm("nop"); |
yishii | 0:65a0ae5578da | 62 | asm("nop"); |
yishii | 0:65a0ae5578da | 63 | asm("nop"); |
yishii | 0:65a0ae5578da | 64 | asm("nop"); |
yishii | 0:65a0ae5578da | 65 | asm("nop"); |
yishii | 0:65a0ae5578da | 66 | asm("nop"); |
yishii | 0:65a0ae5578da | 67 | asm("nop"); |
yishii | 0:65a0ae5578da | 68 | asm("nop"); |
yishii | 0:65a0ae5578da | 69 | asm("nop"); |
yishii | 0:65a0ae5578da | 70 | asm("nop"); |
yishii | 0:65a0ae5578da | 71 | asm("nop"); |
yishii | 0:65a0ae5578da | 72 | #if 0 |
yishii | 0:65a0ae5578da | 73 | asm("nop"); |
yishii | 0:65a0ae5578da | 74 | asm("nop"); |
yishii | 0:65a0ae5578da | 75 | asm("nop"); |
yishii | 0:65a0ae5578da | 76 | asm("nop"); |
yishii | 0:65a0ae5578da | 77 | asm("nop"); |
yishii | 0:65a0ae5578da | 78 | asm("nop"); |
yishii | 0:65a0ae5578da | 79 | asm("nop"); |
yishii | 0:65a0ae5578da | 80 | asm("nop"); |
yishii | 0:65a0ae5578da | 81 | asm("nop"); |
yishii | 0:65a0ae5578da | 82 | asm("nop"); |
yishii | 0:65a0ae5578da | 83 | asm("nop"); |
yishii | 0:65a0ae5578da | 84 | asm("nop"); |
yishii | 0:65a0ae5578da | 85 | asm("nop"); |
yishii | 0:65a0ae5578da | 86 | asm("nop"); |
yishii | 0:65a0ae5578da | 87 | asm("nop"); |
yishii | 0:65a0ae5578da | 88 | asm("nop"); |
yishii | 0:65a0ae5578da | 89 | asm("nop"); |
yishii | 0:65a0ae5578da | 90 | asm("nop"); |
yishii | 0:65a0ae5578da | 91 | asm("nop"); |
yishii | 0:65a0ae5578da | 92 | asm("nop"); |
yishii | 0:65a0ae5578da | 93 | asm("nop"); |
yishii | 0:65a0ae5578da | 94 | asm("nop"); |
yishii | 0:65a0ae5578da | 95 | asm("nop"); |
yishii | 0:65a0ae5578da | 96 | asm("nop"); |
yishii | 0:65a0ae5578da | 97 | asm("nop"); |
yishii | 0:65a0ae5578da | 98 | asm("nop"); |
yishii | 0:65a0ae5578da | 99 | asm("nop"); |
yishii | 0:65a0ae5578da | 100 | asm("nop"); |
yishii | 0:65a0ae5578da | 101 | asm("nop"); |
yishii | 0:65a0ae5578da | 102 | asm("nop"); |
yishii | 0:65a0ae5578da | 103 | asm("nop"); |
yishii | 0:65a0ae5578da | 104 | #endif |
yishii | 0:65a0ae5578da | 105 | } |
yishii | 0:65a0ae5578da | 106 | |
yishii | 0:65a0ae5578da | 107 | inline void sleep0_7us(void) |
yishii | 0:65a0ae5578da | 108 | { |
yishii | 0:65a0ae5578da | 109 | asm("nop"); |
yishii | 0:65a0ae5578da | 110 | asm("nop"); |
yishii | 0:65a0ae5578da | 111 | asm("nop"); |
yishii | 0:65a0ae5578da | 112 | asm("nop"); |
yishii | 0:65a0ae5578da | 113 | asm("nop"); |
yishii | 0:65a0ae5578da | 114 | asm("nop"); |
yishii | 0:65a0ae5578da | 115 | asm("nop"); |
yishii | 0:65a0ae5578da | 116 | asm("nop"); |
yishii | 0:65a0ae5578da | 117 | asm("nop"); |
yishii | 0:65a0ae5578da | 118 | asm("nop"); |
yishii | 0:65a0ae5578da | 119 | asm("nop"); |
yishii | 0:65a0ae5578da | 120 | asm("nop"); |
yishii | 0:65a0ae5578da | 121 | asm("nop"); |
yishii | 0:65a0ae5578da | 122 | asm("nop"); |
yishii | 0:65a0ae5578da | 123 | asm("nop"); |
yishii | 0:65a0ae5578da | 124 | asm("nop"); |
yishii | 0:65a0ae5578da | 125 | asm("nop"); |
yishii | 0:65a0ae5578da | 126 | asm("nop"); |
yishii | 0:65a0ae5578da | 127 | asm("nop"); |
yishii | 0:65a0ae5578da | 128 | asm("nop"); |
yishii | 0:65a0ae5578da | 129 | asm("nop"); |
yishii | 0:65a0ae5578da | 130 | asm("nop"); |
yishii | 0:65a0ae5578da | 131 | asm("nop"); |
yishii | 0:65a0ae5578da | 132 | asm("nop"); |
yishii | 0:65a0ae5578da | 133 | asm("nop"); |
yishii | 0:65a0ae5578da | 134 | asm("nop"); |
yishii | 0:65a0ae5578da | 135 | asm("nop"); |
yishii | 0:65a0ae5578da | 136 | asm("nop"); |
yishii | 0:65a0ae5578da | 137 | asm("nop"); |
yishii | 0:65a0ae5578da | 138 | asm("nop"); |
yishii | 0:65a0ae5578da | 139 | #if 0 |
yishii | 0:65a0ae5578da | 140 | asm("nop"); |
yishii | 0:65a0ae5578da | 141 | asm("nop"); |
yishii | 0:65a0ae5578da | 142 | asm("nop"); |
yishii | 0:65a0ae5578da | 143 | asm("nop"); |
yishii | 0:65a0ae5578da | 144 | asm("nop"); |
yishii | 0:65a0ae5578da | 145 | asm("nop"); |
yishii | 0:65a0ae5578da | 146 | asm("nop"); |
yishii | 0:65a0ae5578da | 147 | asm("nop"); |
yishii | 0:65a0ae5578da | 148 | asm("nop"); |
yishii | 0:65a0ae5578da | 149 | asm("nop"); |
yishii | 0:65a0ae5578da | 150 | asm("nop"); |
yishii | 0:65a0ae5578da | 151 | asm("nop"); |
yishii | 0:65a0ae5578da | 152 | asm("nop"); |
yishii | 0:65a0ae5578da | 153 | asm("nop"); |
yishii | 0:65a0ae5578da | 154 | asm("nop"); |
yishii | 0:65a0ae5578da | 155 | asm("nop"); |
yishii | 0:65a0ae5578da | 156 | asm("nop"); |
yishii | 0:65a0ae5578da | 157 | asm("nop"); |
yishii | 0:65a0ae5578da | 158 | asm("nop"); |
yishii | 0:65a0ae5578da | 159 | asm("nop"); |
yishii | 0:65a0ae5578da | 160 | #endif |
yishii | 0:65a0ae5578da | 161 | } |
yishii | 0:65a0ae5578da | 162 | |
yishii | 0:65a0ae5578da | 163 | inline void sleep0_6us(void) |
yishii | 0:65a0ae5578da | 164 | { |
yishii | 0:65a0ae5578da | 165 | asm("nop"); |
yishii | 0:65a0ae5578da | 166 | asm("nop"); |
yishii | 0:65a0ae5578da | 167 | asm("nop"); |
yishii | 0:65a0ae5578da | 168 | asm("nop"); |
yishii | 0:65a0ae5578da | 169 | asm("nop"); |
yishii | 0:65a0ae5578da | 170 | asm("nop"); |
yishii | 0:65a0ae5578da | 171 | asm("nop"); |
yishii | 0:65a0ae5578da | 172 | asm("nop"); |
yishii | 0:65a0ae5578da | 173 | asm("nop"); |
yishii | 0:65a0ae5578da | 174 | asm("nop"); |
yishii | 0:65a0ae5578da | 175 | asm("nop"); |
yishii | 0:65a0ae5578da | 176 | asm("nop"); |
yishii | 0:65a0ae5578da | 177 | asm("nop"); |
yishii | 0:65a0ae5578da | 178 | #if 0 |
yishii | 0:65a0ae5578da | 179 | asm("nop"); |
yishii | 0:65a0ae5578da | 180 | asm("nop"); |
yishii | 0:65a0ae5578da | 181 | asm("nop"); |
yishii | 0:65a0ae5578da | 182 | asm("nop"); |
yishii | 0:65a0ae5578da | 183 | asm("nop"); |
yishii | 0:65a0ae5578da | 184 | asm("nop"); |
yishii | 0:65a0ae5578da | 185 | asm("nop"); |
yishii | 0:65a0ae5578da | 186 | asm("nop"); |
yishii | 0:65a0ae5578da | 187 | asm("nop"); |
yishii | 0:65a0ae5578da | 188 | asm("nop"); |
yishii | 0:65a0ae5578da | 189 | asm("nop"); |
yishii | 0:65a0ae5578da | 190 | asm("nop"); |
yishii | 0:65a0ae5578da | 191 | asm("nop"); |
yishii | 0:65a0ae5578da | 192 | asm("nop"); |
yishii | 0:65a0ae5578da | 193 | asm("nop"); |
yishii | 0:65a0ae5578da | 194 | asm("nop"); |
yishii | 0:65a0ae5578da | 195 | asm("nop"); |
yishii | 0:65a0ae5578da | 196 | asm("nop"); |
yishii | 0:65a0ae5578da | 197 | asm("nop"); |
yishii | 0:65a0ae5578da | 198 | asm("nop"); |
yishii | 0:65a0ae5578da | 199 | asm("nop"); |
yishii | 0:65a0ae5578da | 200 | asm("nop"); |
yishii | 0:65a0ae5578da | 201 | asm("nop"); |
yishii | 0:65a0ae5578da | 202 | asm("nop"); |
yishii | 0:65a0ae5578da | 203 | asm("nop"); |
yishii | 0:65a0ae5578da | 204 | asm("nop"); |
yishii | 0:65a0ae5578da | 205 | asm("nop"); |
yishii | 0:65a0ae5578da | 206 | asm("nop"); |
yishii | 0:65a0ae5578da | 207 | asm("nop"); |
yishii | 0:65a0ae5578da | 208 | asm("nop"); |
yishii | 0:65a0ae5578da | 209 | #endif |
yishii | 0:65a0ae5578da | 210 | } |
yishii | 0:65a0ae5578da | 211 | |
yishii | 0:65a0ae5578da | 212 | inline void led_bit_0(void){ |
yishii | 0:65a0ae5578da | 213 | pinLed = 1; |
yishii | 0:65a0ae5578da | 214 | sleep0_35us(); |
yishii | 0:65a0ae5578da | 215 | pinLed = 0; |
yishii | 0:65a0ae5578da | 216 | sleep0_8us(); |
yishii | 0:65a0ae5578da | 217 | } |
yishii | 0:65a0ae5578da | 218 | |
yishii | 0:65a0ae5578da | 219 | inline void led_bit_1(void){ |
yishii | 0:65a0ae5578da | 220 | pinLed = 1; |
yishii | 0:65a0ae5578da | 221 | sleep0_7us(); |
yishii | 0:65a0ae5578da | 222 | pinLed = 0; |
yishii | 0:65a0ae5578da | 223 | sleep0_6us(); |
yishii | 0:65a0ae5578da | 224 | } |
yishii | 0:65a0ae5578da | 225 | |
yishii | 0:65a0ae5578da | 226 | |
yishii | 0:65a0ae5578da | 227 | void TaskLed(void const *argument) |
yishii | 0:65a0ae5578da | 228 | { |
yishii | 0:65a0ae5578da | 229 | int i; |
yishii | 0:65a0ae5578da | 230 | int j; |
yishii | 0:65a0ae5578da | 231 | int k; |
yishii | 0:65a0ae5578da | 232 | int8_t val = 255; |
yishii | 0:65a0ae5578da | 233 | |
yishii | 0:65a0ae5578da | 234 | while(1){ |
yishii | 0:65a0ae5578da | 235 | StatusLED = 1; |
yishii | 0:65a0ae5578da | 236 | Thread::wait(100); |
yishii | 0:65a0ae5578da | 237 | StatusLED = 0; |
yishii | 0:65a0ae5578da | 238 | Thread::wait(100); |
yishii | 0:65a0ae5578da | 239 | |
yishii | 0:65a0ae5578da | 240 | for(i=0;i<NUMBER_OF_LEDS;i++){ |
yishii | 0:65a0ae5578da | 241 | for(j=0;j<3;j++){ |
yishii | 0:65a0ae5578da | 242 | for(k=0;k<8;k++){ |
yishii | 0:65a0ae5578da | 243 | if((val >> (7-k)) & 0x01){ |
yishii | 0:65a0ae5578da | 244 | led_bit_1(); |
yishii | 0:65a0ae5578da | 245 | } else { |
yishii | 0:65a0ae5578da | 246 | led_bit_0(); |
yishii | 0:65a0ae5578da | 247 | } |
yishii | 0:65a0ae5578da | 248 | } |
yishii | 0:65a0ae5578da | 249 | } |
yishii | 0:65a0ae5578da | 250 | } |
yishii | 0:65a0ae5578da | 251 | val-=20; |
yishii | 0:65a0ae5578da | 252 | } |
yishii | 0:65a0ae5578da | 253 | } |
yishii | 0:65a0ae5578da | 254 | /* |
yishii | 0:65a0ae5578da | 255 | * WS2812 tape led IC |
yishii | 0:65a0ae5578da | 256 | * |
yishii | 0:65a0ae5578da | 257 | * 0.35us 0.8us (+-150ns) |
yishii | 0:65a0ae5578da | 258 | * 0: |^^^^^|__________| |
yishii | 0:65a0ae5578da | 259 | * |
yishii | 0:65a0ae5578da | 260 | * 0.7us 0.6us (+-150ns) |
yishii | 0:65a0ae5578da | 261 | * 1: |^^^^^^^^^^|_____| |
yishii | 0:65a0ae5578da | 262 | * |
yishii | 0:65a0ae5578da | 263 | * >50us |
yishii | 0:65a0ae5578da | 264 | * RESET: |________________| |
yishii | 0:65a0ae5578da | 265 | */ |
yishii | 0:65a0ae5578da | 266 |