|
| 1 | +/* |
| 2 | + * test spi functions |
| 3 | + */ |
| 4 | + |
| 5 | +#include "Arduino.h" |
| 6 | +#include "wiring_private.h" |
| 7 | + |
| 8 | +void pinMode1(uint8_t pin, uint8_t mode) |
| 9 | +{ |
| 10 | + uint8_t bit = digitalPinToBitMask(pin); |
| 11 | + uint8_t port = digitalPinToPort(pin); |
| 12 | + volatile GPIO_TypeDef *gpio; |
| 13 | + |
| 14 | + if (port == NOT_A_PIN) return; |
| 15 | + |
| 16 | + gpio = (GPIO_TypeDef *) portOutputRegister(port); |
| 17 | + |
| 18 | + if (mode == INPUT) { |
| 19 | + BEGIN_CRITICAL |
| 20 | + gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 21 | + gpio->CR1 &= ~bit; // release top side |
| 22 | + gpio->DDR &= ~bit; // now set direction |
| 23 | + END_CRITICAL |
| 24 | + } else if (mode == INPUT_PULLUP) { |
| 25 | + BEGIN_CRITICAL |
| 26 | + gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 27 | + gpio->DDR &= ~bit; // set direction before |
| 28 | + gpio->CR1 |= bit; // activating the pull up |
| 29 | + END_CRITICAL |
| 30 | + } else if (mode == OUTPUT_FAST) {// output push-pull, fast |
| 31 | + BEGIN_CRITICAL |
| 32 | + gpio->CR1 |= bit; |
| 33 | + gpio->DDR |= bit; // direction before setting CR2 to |
| 34 | + gpio->CR2 |= bit; // avoid accidental interrupt |
| 35 | + END_CRITICAL |
| 36 | + } else if (mode == OUTPUT_OD_FAST) { // output open drain, fast |
| 37 | + BEGIN_CRITICAL |
| 38 | + gpio->CR1 &= ~bit; |
| 39 | + gpio->DDR |= bit; // direction before setting CR2 to |
| 40 | + gpio->CR2 |= bit; // avoid accidental interrupt |
| 41 | + END_CRITICAL |
| 42 | + } else if (mode == OUTPUT_OD) { // output open drain, slow |
| 43 | + BEGIN_CRITICAL |
| 44 | + gpio->CR1 &= ~bit; |
| 45 | + gpio->CR2 &= ~bit; |
| 46 | + gpio->DDR |= bit; |
| 47 | + END_CRITICAL |
| 48 | + } else { // output push-pull, slow |
| 49 | + BEGIN_CRITICAL |
| 50 | + gpio->CR1 |= bit; |
| 51 | + gpio->CR2 &= ~bit; |
| 52 | + gpio->DDR |= bit; |
| 53 | + END_CRITICAL |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +#if 0 |
| 58 | + if (mode == INPUT) { |
| 59 | + gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 60 | + gpio->CR1 &= ~bit; // release top side |
| 61 | + gpio->DDR &= ~bit; // now set direction |
| 62 | + } else if (mode == INPUT_PULLUP) { |
| 63 | + gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 64 | + gpio->DDR &= ~bit; // set direction before |
| 65 | + gpio->CR1 |= bit; // activating the pull up |
| 66 | + |
| 67 | + } else if (mode == OUTPUT_FAST) {// output push-pull, fast |
| 68 | + gpio->CR1 |= bit; |
| 69 | + gpio->DDR |= bit; // direction before setting CR2 to |
| 70 | + gpio->CR2 |= bit; // avoid accidental interrupt |
| 71 | + } else if (mode == OUTPUT_OD_FAST) { // output open drain, fast |
| 72 | + gpio->CR1 &= ~bit; |
| 73 | + gpio->DDR |= bit; // direction before setting CR2 to |
| 74 | + gpio->CR2 |= bit; // avoid accidental interrupt |
| 75 | + |
| 76 | + } else if (mode == OUTPUT_OD) { // output open drain, slow |
| 77 | + gpio->CR1 &= ~bit; |
| 78 | + gpio->CR2 &= ~bit; |
| 79 | + gpio->DDR |= bit; |
| 80 | + } else { // output push-pull, slow |
| 81 | + gpio->CR1 |= bit; |
| 82 | + gpio->CR2 &= ~bit; |
| 83 | + gpio->DDR |= bit; |
| 84 | + } |
| 85 | +#endif |
| 86 | + |
| 87 | + |
| 88 | +// |
| 89 | +void pinMode_asm(uint8_t pin, uint8_t mode) |
| 90 | +{ |
| 91 | +__asm |
| 92 | + sub sp, #16 |
| 93 | +; pinmode.c: 10: uint8_t bit = digitalPinToBitMask(pin); |
| 94 | + ldw x, #_digital_pin_to_bit_mask_PGM+0 |
| 95 | + ld a, xl |
| 96 | + add a, (0x13, sp) |
| 97 | + rlwa x |
| 98 | + adc a, #0x00 |
| 99 | + ld xh, a |
| 100 | + ld a, (x) |
| 101 | + ld (0x04, sp), a |
| 102 | +; pinmode.c: 11: uint8_t port = digitalPinToPort(pin); |
| 103 | + ldw x, #_digital_pin_to_port_PGM+0 |
| 104 | + ld a, xl |
| 105 | + add a, (0x13, sp) |
| 106 | + rlwa x |
| 107 | + adc a, #0x00 |
| 108 | + ld xh, a |
| 109 | + ld a, (x) |
| 110 | + ld (0x03, sp), a |
| 111 | + ld a, (0x03, sp) |
| 112 | + ld (0x07, sp), a |
| 113 | +; pinmode.c: 14: if (port == NOT_A_PIN) return; |
| 114 | + tnz (0x03, sp) |
| 115 | + jrne 00002$ |
| 116 | + jp 00018$ |
| 117 | +00002$: |
| 118 | +; pinmode.c: 16: gpio = (GPIO_TypeDef *) portOutputRegister(port); |
| 119 | + ldw x, #_port_to_output_PGM+0 |
| 120 | + ldw (0x0e, sp), x |
| 121 | + ld a, (0x07, sp) |
| 122 | + ld xl, a |
| 123 | + ld a, #0x02 |
| 124 | + mul x, a |
| 125 | + addw x, (0x0e, sp) |
| 126 | + ldw x, (x) ; jetzt ist gpio in x |
| 127 | + |
| 128 | + ld a, (0x10, sp) ; bit |
| 129 | + ld yl,a ; yl = bit |
| 130 | + cpl a |
| 131 | + ld yh,a ; yh = ~bit |
| 132 | + ld a, (0x14, sp) ; a=mode, flags are set |
| 133 | + |
| 134 | +; gpio->DDR: (2,x) (war an c,SP) |
| 135 | +; gpio->CR1: (3,x) (war an 8,SP) |
| 136 | +; gpio->CR2: (4,x) (war an 5,SP) |
| 137 | + |
| 138 | + sim |
| 139 | +; pinmode.c: 18: if (mode == INPUT) { |
| 140 | + jrne 00016$ |
| 141 | +; pinmode.c: 20: gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 142 | + ld a,yh |
| 143 | + and a,(4,x) |
| 144 | + ld (4,x),a |
| 145 | +; pinmode.c: 21: gpio->CR1 &= ~bit; // release top side |
| 146 | + ld a,yh |
| 147 | + and a,(3,x) |
| 148 | + ld (3,x),a |
| 149 | +; pinmode.c: 22: gpio->DDR &= ~bit; // now set direction |
| 150 | + ld a,yh |
| 151 | + and a,(2,x) |
| 152 | + jp 00022$ |
| 153 | + |
| 154 | +00016$: |
| 155 | +; pinmode.c: 24: } else if (mode == INPUT_PULLUP) { |
| 156 | + cp a, #0x02 |
| 157 | + jrne 00013$ |
| 158 | +; pinmode.c: 26: gpio->CR2 &= ~bit; // first: deactivate interrupt |
| 159 | + ld a,yh |
| 160 | + and a,(4,x) |
| 161 | + ld (4,x),a |
| 162 | +; pinmode.c: 27: gpio->DDR &= ~bit; // set direction before |
| 163 | + ld a,yh |
| 164 | + and a,(2,x) |
| 165 | + ld (2,x),a |
| 166 | +; pinmode.c: 28: gpio->CR1 |= bit; // activating the pull up |
| 167 | + ld a,yl |
| 168 | + or a,(3,x) |
| 169 | + ld (3,x),a |
| 170 | + jp 00018$ |
| 171 | + |
| 172 | +00013$: |
| 173 | +; pinmode.c: 30: } else if (mode == OUTPUT_FAST) {// output push-pull, fast |
| 174 | + cp a, #0x05 |
| 175 | + jrne 00010$ |
| 176 | +; pinmode.c: 32: gpio->CR1 |= bit; |
| 177 | + ld a,yl |
| 178 | + or a,(3,x) |
| 179 | + jra 00020$ |
| 180 | +; pinmode.c: 39: gpio->DDR |= bit; // direction before setting CR2 to |
| 181 | +; pinmode.c: 40: gpio->CR2 |= bit; // avoid accidental interrupt |
| 182 | +00010$: |
| 183 | +; pinmode.c: 36: } else if (mode == OUTPUT_OD_FAST) { // output open drain, fast |
| 184 | + cp a, #0x07 |
| 185 | + jrne 00007$ |
| 186 | +; pinmode.c: 38: gpio->CR1 &= ~bit; |
| 187 | + ld a,yh |
| 188 | + and a,(3,x) |
| 189 | +00020$: ld (3,x),a |
| 190 | +; pinmode.c: 39: gpio->DDR |= bit; // direction before setting CR2 to |
| 191 | + ld a,yl |
| 192 | + or a,(2,x) |
| 193 | + ld (2,x),a |
| 194 | +; pinmode.c: 40: gpio->CR2 |= bit; // avoid accidental interrupt |
| 195 | + ld a,yl |
| 196 | + or a,(4,x) |
| 197 | + ld (4,x),a |
| 198 | + jra 00018$ |
| 199 | + |
| 200 | +00007$: |
| 201 | +; pinmode.c: 42: } else if (mode == OUTPUT_OD) { // output open drain, slow |
| 202 | + cp a, #0x03 |
| 203 | + jrne 00004$ |
| 204 | +; pinmode.c: 44: gpio->CR1 &= ~bit; |
| 205 | + ld a,yh |
| 206 | + and a,(3,x) |
| 207 | + jra 00021$ |
| 208 | +; pinmode.c: 45: gpio->CR2 &= ~bit; |
| 209 | +; pinmode.c: 46: gpio->DDR |= bit; |
| 210 | +00004$: |
| 211 | +; pinmode.c: 50: gpio->CR1 |= bit; |
| 212 | + ld a,yl |
| 213 | + or a,(3,x) |
| 214 | +00021$: ld (3,x),a |
| 215 | +; pinmode.c: 51: gpio->CR2 &= ~bit; |
| 216 | + ld a,yh |
| 217 | + and a,(4,x) |
| 218 | + ld (4,x),a |
| 219 | +; pinmode.c: 52: gpio->DDR |= bit; |
| 220 | + ld a,yl |
| 221 | + or a,(2,x) |
| 222 | +00022$: ld (2,x),a |
| 223 | +00018$: |
| 224 | + rim |
| 225 | + addw sp, #16 |
| 226 | +__endasm; |
| 227 | +} |
| 228 | +// |
| 229 | + |
| 230 | + |
| 231 | +void setup(void) |
| 232 | +{ |
| 233 | + pinMode1(1,OUTPUT); |
| 234 | +} |
| 235 | + |
| 236 | + |
| 237 | +void loop (void) |
| 238 | +{ |
| 239 | +} |
0 commit comments