8000 Start on rotaryio.IncrementalEncoder adafruit/circuitpython#1045 (doe… · ihassin/circuitpython@ee21cc1 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee21cc1

Browse files
committed
Start on rotaryio.IncrementalEncoder adafruit#1045 (does nothing yet!)
1 parent 765d877 commit ee21cc1

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

ports/nrf/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ SRC_COMMON_HAL += \
166166
pulseio/PulseIn.c \
167167
pulseio/PulseOut.c \
168168
pulseio/__init__.c \
169+
rotaryio/__init__.c \
170+
rotaryio/IncrementalEncoder.c \
169171
supervisor/Runtime.c \
170172
supervisor/__init__.c \
171173
time/__init__.c \
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Nick Moore for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "common-hal/rotaryio/IncrementalEncoder.h"
28+
29+
#include "py/runtime.h"
30+
31+
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t* self,
32+
const mcu_pin_obj_t* pin_a, const mcu_pin_obj_t* pin_b) {
33+
34+
claim_pin(pin_a);
35+
claim_pin(pin_b);
36+
}
37+
38+
bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incrementalencoder_obj_t* self) {
39+
return self->pin_a == NO_PIN;
40+
}
41+
42+
void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_obj_t* self) {
43+
if (common_hal_rotaryio_incrementalencoder_deinited(self)) {
44+
return;
45+
}
46+
reset_pin_number(self->pin_a);
47+
self->pin_a = NO_PIN;
48+
reset_pin_number(self->pin_b);
49+
self->pin_b = NO_PIN;
50+
}
51+
52+
mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementalencoder_obj_t* self) {
53+
return self->position;
54+
}
55+
56+
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t* self,
57+
mp_int_t new_position) {
58+
self->position = new_position;
59+
}
60+
61+
void incrementalencoder_interrupt_handler(uint8_t channel) {
62+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ROTARYIO_INCREMENTALENCODER_H
28+
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ROTARYIO_INCREMENTALENCODER_H
29+
30+
#include "common-hal/microcontroller/Pin.h"
31+
32+
#include "py/obj.h"
33+
34+
typedef struct {
35+
mp_obj_base_t base;
36+
uint8_t pin_a;
37+
uint8_t pin_b;
38+
mp_int_t position;
39+
} rotaryio_incrementalencoder_obj_t;
40+
41+
42+
void incrementalencoder_interrupt_handler(uint8_t channel);
43+
44+
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ROTARYIO_INCREMENTALENCODER_H
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// No rotaryio module functions.

ports/nrf/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ extern const struct _mp_obj_module_t busio_module;
169169
extern const struct _mp_obj_module_t board_module;
170170
extern const struct _mp_obj_module_t os_module;
171171
extern const struct _mp_obj_module_t random_module;
172+
extern const struct _mp_obj_module_t rotaryio_module;
172173
extern const struct _mp_obj_module_t storage_module;
173174
extern const struct _mp_obj_module_t struct_module;
174175
extern const struct _mp_obj_module_t time_module;
@@ -205,6 +206,7 @@ extern const struct _mp_obj_module_t touchio_module;
205206
{ MP_OBJ_NEW_QSTR (MP_QSTR_bitbangio ), (mp_obj_t)&bitbangio_module }, \
206207
{ MP_OBJ_NEW_QSTR (MP_QSTR_os ), (mp_obj_t)&os_module }, \
207208
{ MP_OBJ_NEW_QSTR (MP_QSTR_random ), (mp_obj_t)&random_module }, \
209+
{ MP_OBJ_NEW_QSTR (MP_QSTR_rotaryio ), (mp_obj_t)&rotaryio_module }, \
208210
{ MP_OBJ_NEW_QSTR (MP_QSTR_storage ), (mp_obj_t)&storage_module }, \
209211
{ MP_OBJ_NEW_QSTR (MP_QSTR_struct ), (mp_obj_t)&struct_module }, \
210212
{ MP_OBJ_NEW_QSTR (MP_QSTR_supervisor ), (mp_obj_t)&supervisor_module }, \

0 commit comments

Comments
 (0)
0