Skip to content

Commit 207369e

Browse files
committed
Add boilerplate, create basic PWMOut test
1 parent a6c2020 commit 207369e

File tree

8 files changed

+395
-1
lines changed

8 files changed

+395
-1
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
7+
* Uses code from Micropython, Copyright (c) 2013-2016 Damien P. George
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
29+
#include "common-hal/pulseio/PWMOut.h"
30+
#include "shared-bindings/pulseio/PWMOut.h"
31+
#include "py/runtime.h"
32+
#include "driver/ledc.h"
33+
34+
#define LEDC_LS_TIMER LEDC_TIMER_1
35+
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
36+
#define LEDC_LS_CH0_GPIO (18)
37+
#define LEDC_LS_CH0_CHANNEL LEDC_CHANNEL_0
38+
#define LEDC_LS_CH1_GPIO (19)
39+
#define LEDC_LS_CH1_CHANNEL LEDC_CHANNEL_1
40+
#define LEDC_LS_CH2_GPIO (4)
41+
#define LEDC_LS_CH2_CHANNEL LEDC_CHANNEL_2
42+
#define LEDC_LS_CH3_GPIO (5)
43+
#define LEDC_LS_CH3_CHANNEL LEDC_CHANNEL_3
44+
45+
#define LEDC_TEST_CH_NUM (4)
46+
#define LEDC_TEST_DUTY (4000)
47+
#define LEDC_TEST_FADE_TIME (3000)
48+
49+
50+
51+
void pwmout_reset(void) {
52+
}
53+
54+
pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
55+
const mcu_pin_obj_t* pin,
56+
uint16_t duty,
57+
uint32_t frequency,
58+
bool variable_frequency) {
59+
ledc_timer_config_t ledc_timer = {
60+
.duty_resolution = LEDC_TIMER_16_BIT, // resolution of PWM duty
61+
.freq_hz = frequency, // frequency of PWM signal
62+
.speed_mode = LEDC_LS_MODE, // timer mode
63+
.timer_num = LEDC_LS_TIMER, // timer index
64+
.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
65+
};
66+
// Set configuration of timer0 for high speed channels
67+
ledc_timer_config(&ledc_timer);
68+
69+
ledc_channel_config_t pwm_channel = {
70+
.channel = LEDC_LS_CH0_CHANNEL,
71+
.duty = 0,
72+
.gpio_num = pin->number,
73+
.speed_mode = LEDC_LS_MODE,
74+
.hpoint = 0,
75+
.timer_sel = LEDC_LS_TIMER
76+
};
77+
78+
// Set LED Controller with previously prepared configuration
79+
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
80+
ledc_channel_config(&ledc_channel[ch]);
81+
}
82+
83+
for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
84+
ledc_set_duty(ledc_channel[ch].speed_mode, ledc_channel[ch].channel, duty*2);
85+
ledc_update_duty(ledc_channel[ch].speed_mode, ledc_channel[ch].channel);
86+
}
87+
88+
return PWMOUT_OK;
89+
}
90+
91+
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
92+
}
93+
94+
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
95+
}
96+
97+
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
98+
return false;
99+
}
100+
101+
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
102+
}
103+
104+
void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
105+
}
106+
107+
uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
108+
return false;
109+
}
110+
111+
void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) {
112+
}
113+
114+
uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
115+
return false;
116+
}
117+
118+
bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self) {
119+
return false;
120+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland 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_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H
29+
30+
#include "common-hal/microcontroller/Pin.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
uint8_t channel;
35+
bool variable_frequency: 1;
36+
uint16_t duty_cycle;
37+
uint32_t frequency;
38+
uint32_t period;
39+
} pulseio_pwmout_obj_t;
40+
41+
void pwmout_reset(void);
42+
43+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Lucian Copeland 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/pulseio/PulseIn.h"
28+
#include "py/runtime.h"
29+
30+
// STATIC void pulsein_handler(uint8_t num) {
31+
// }
32+
33+
void pulsein_reset(void) {
34+
}
35+
36+
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu_pin_obj_t* pin,
37+
uint16_t maxlen, bool idle_state) {
38+
mp_raise_NotImplementedError(translate("PulseIn not supported on this chip"));
39+
}
40+
41+
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
42+
return false;
43+
}
44+
45+
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
46+
}
47+
48+
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) {
49+
}
50+
51+
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, uint16_t trigger_duration) {
52+
}
53+
54+
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
55+
}
56+
57+
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, int16_t index) {
58+
return false;
59+
}
60+
61+
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
62+
return false;
63+
}
64+
65+
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
66+
return false;
67+
}
68+
69+
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
70+
return false;
71+
}
72+
73+
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
74+
return false;
75+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland 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_ESP32S2_COMMON_HAL_PULSEIO_PULSEIN_H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEIN_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+
37+
const mcu_pin_obj_t* pin;
38+
bool idle_state;
39+
bool paused;
40+
volatile bool first_edge;
41+
42+
uint16_t* buffer;
43+
uint16_t maxlen;
44+
45+
volatile uint16_t start;
46+
volatile uint16_t len;
47+
volatile uint32_t last_overflow;
48+
volatile uint16_t last_count;
49+
} pulseio_pulsein_obj_t;
50+
51+
void pulsein_reset(void);
52+
53+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEIN_H
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland 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/pulseio/PulseOut.h"
28+
29+
#include "shared-bindings/pulseio/PWMOut.h"
30+
#include "py/runtime.h"
31+
32+
// STATIC void turn_on(pulseio_pulseout_obj_t *pulseout) {
33+
// }
34+
35+
// STATIC void turn_off(pulseio_pulseout_obj_t *pulseout) {
36+
// }
37+
38+
// STATIC void start_timer(void) {
39+
// }
40+
41+
// STATIC void pulseout_event_handler(void) {
42+
// }
43+
44+
void pulseout_reset() {
45+
}
46+
47+
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
48+
const pulseio_pwmout_obj_t* carrier) {
49+
mp_raise_NotImplementedError(translate("PulseOut not supported on this chip"));
50+
}
51+
52+
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self) {
53+
return false;
54+
}
55+
56+
void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
57+
}
58+
59+
void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) {
60+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland 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_ESP32S2_COMMON_HAL_PULSEIO_PULSEOUT_H
28+
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEOUT_H
29+
30+
#include "common-hal/microcontroller/Pin.h"
31+
#include "common-hal/pulseio/PWMOut.h"
32+
33+
#include "py/obj.h"
34+
35+
typedef struct {
36+
mp_obj_base_t base;
37+
pulseio_pwmout_obj_t *pwmout;
38+
} pulseio_pulseout_obj_t;
39+
40+
void pulseout_reset(void);
41+
42+
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEOUT_H

0 commit comments

Comments
 (0)