Skip to content

Commit ca18193

Browse files
author
Martino Facchin
committed
pulseIn: support PORTE to PORTG
ArduinoMega uses also PORTE
1 parent 1970a02 commit ca18193

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

hardware/arduino/avr/cores/arduino/wiring_private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ uint16_t countPulseASM_B(const uint8_t port, const uint8_t bit, uint16_t maxloop
4848
uint16_t countPulseASM_C(const uint8_t port, const uint8_t bit, uint16_t maxloops, uint8_t state);
4949
uint16_t countPulseASM_D(const uint8_t port, const uint8_t bit, uint16_t maxloops, uint8_t state);
5050

51+
#if defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)
52+
uint16_t countPulseASM_E(const uint8_t port, const uint8_t bit, uint16_t maxloops, uint8_t state);
53+
uint16_t countPulseASM_F(const uint8_t port, const uint8_t bit, uint16_t maxloops, uint8_t state);
54+
uint16_t countPulseASM_G(const uint8_t port, const uint8_t bit, uint16_t maxloops, uint8_t state);
55+
#endif
56+
5157
#define EXTERNAL_INT_0 0
5258
#define EXTERNAL_INT_1 1
5359
#define EXTERNAL_INT_2 2

hardware/arduino/avr/cores/arduino/wiring_pulse.S

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,90 @@ mov r25,r1
135135
exit_d:
136136
pop r17
137137
ret
138+
139+
140+
#if defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)
141+
142+
.global countPulseASM_E
143+
.global countPulseASM_F
144+
.global countPulseASM_G
145+
146+
countPulseASM_E:
147+
push r17
148+
mov r24,r1
149+
mov r25,r1
150+
loop_e:
151+
adiw r24, 1
152+
cp r24, r20
153+
cpc r25, r21
154+
breq return_zero_e
155+
//check the pin state to be consistent with the mask
156+
in r17, PINE-0x20
157+
eor r17, r18
158+
and r17, r22
159+
cpi r17, 0
160+
breq loop_e
161+
//sbic PINE-0x20, 7
162+
//rjmp loop
163+
ret_delay_e:
164+
rjmp exit_e
165+
return_zero_e:
166+
mov r24,r1
167+
mov r25,r1
168+
exit_e:
169+
pop r17
170+
ret
171+
172+
countPulseASM_F:
173+
push r17
174+
mov r24,r1
175+
mov r25,r1
176+
loop_f:
177+
adiw r24, 1
178+
cp r24, r20
179+
cpc r25, r21
180+
breq return_zero_f
181+
//check the pin state to be consistent with the mask
182+
in r17, PINF-0x20
183+
eor r17, r18
184+
and r17, r22
185+
cpi r17, 0
186+
breq loop_f
187+
//sbic PINF-0x20, 7
188+
//rjmp loop
189+
ret_delay_f:
190+
rjmp exit_f
191+
return_zero_f:
192+
mov r24,r1
193+
mov r25,r1
194+
exit_f:
195+
pop r17
196+
ret
197+
198+
countPulseASM_G:
199+
push r17
200+
mov r24,r1
201+
mov r25,r1
202+
loop_g:
203+
adiw r24, 1
204+
cp r24, r20
205+
cpc r25, r21
206+
breq return_zero_g
207+
//check the pin state to be consistent with the mask
208+
in r17, PING-0x20
209+
eor r17, r18
210+
and r17, r22
211+
cpi r17, 0
212+
breq loop_g
213+
//sbic PING-0x20, 7
214+
//rjmp loop
215+
ret_delay_g:
216+
rjmp exit_g
217+
return_zero_g:
218+
mov r24,r1
219+
mov r25,r1
220+
exit_g:
221+
pop r17
222+
ret
223+
224+
#endif

hardware/arduino/avr/cores/arduino/wiring_pulse.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
7474
//portD
7575
countPulseASM = &countPulseASM_D;
7676
break;
77+
#if defined(__AVR_ATmega1280__)||defined(__AVR_ATmega2560__)
78+
case PE:
79+
//portE
80+
countPulseASM = &countPulseASM_E;
81+
case PF:
82+
//portF
83+
countPulseASM = &countPulseASM_F;
84+
case PG:
85+
//portG
86+
countPulseASM = &countPulseASM_G;
87+
#endif
7788
default:
7889
return 0;
7990
}

0 commit comments

Comments
 (0)