Commit d5e25648 authored by Daniel Campora's avatar Daniel Campora

cc3200: Re-work Pin class according to the new API.

Also add relevant test.
parent 42054c3c
Pin,Name,Default,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF14,AF15,ADC Pin,Name,Default,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF14,AF15,ADC
1,GP10,GP10,GP10,I2C_SCL,,GT_PWM06,,,SDCARD_CLK,UART1_TX,,,,,GT_CCP01,,,, 1,GP10,GP10,GP10,I2C0_SCL,,TIM3_PWM0,,,SD0_CLK,UART1_TX,,,,,TIM0_CC1,,,,
2,GP11,GP11,GP11,I2C_SDA,,GT_PWM07,pXCLK(XVCLK),,SDCARD_CMD,UART1_RX,,,,,GT_CCP02,McAFSX,,, 2,GP11,GP11,GP11,I2C0_SDA,,TIM3_PWM1,pXCLK(XVCLK),,SD0_CMD,UART1_RX,,,,,TIM1_CC0,I2S0_FS,,,
3,GP12,GP12,GP12,,,McACLK,pVS(VSYNC),I2C_SCL,,UART0_TX,,,,,GT_CCP03,,,, 3,GP12,GP12,GP12,,,I2S0_CLK,pVS(VSYNC),I2C0_SCL,,UART0_TX,,,,,TIM1_CC1,,,,
4,GP13,GP13,GP13,,,,pHS(HSYNC),I2C_SDA,,UART0_RX,,,,,GT_CCP04,,,, 4,GP13,GP13,GP13,,,,pHS(HSYNC),I2C0_SDA,,UART0_RX,,,,,TIM2_CC0,,,,
5,GP14,GP14,GP14,,,,pDATA8(CAM_D4),2C_SCL,,GSPI_CLK,,,,,GT_CCP05,,,, 5,GP14,GP14,GP14,,,,pDATA8(CAM_D4),I2C0_SCL,,SPI0_CLK,,,,,TIM2_CC1,,,,
6,GP15,GP15,GP15,,,,pDATA9(CAM_D5),I2C_SDA,,GSPI_MISO,,,,,,GT_CCP06,,, 6,GP15,GP15,GP15,,,,pDATA9(CAM_D5),I2C0_SDA,,SPI0_MISO,,,,,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D1),,I2S0_DAT1,TIM2_CC1,,,,,,,,,ADC0_CH3
61,GP6,GP6,GP6,,,UART1_CTS,pDATA4(CAM_D0),UART0_RTS,UART0_CTS,GT_CCP06,,,,,,,,, 61,GP6,GP6,GP6,,,UART1_CTS,pDATA4(CAM_D0),UART0_RTS,UART0_CTS,TIM3_CC0,,,,,,,,,
62,GP7,GP7,GP7,,,UART1_RTS,,,,,,,UART0_RTS,UART0_TX,,McACLKX,,, 62,GP7,GP7,GP7,,,UART1_RTS,,,,,,,UART0_RTS,UART0_TX,,I2S0_CLK,,,
63,GP8,GP8,GP8,,,,,,SDCARD_IRQ,McAFSX,,,,,GT_CCP06,,,, 63,GP8,GP8,GP8,,,,,,SDCARD_IRQ,I2S0_FS,,,,,TIM3_CC0,,,,
64,GP9,GP9,GP9,,,GT_PWM05,,,SDCARD_DATA,McAXR0,,,,,GT_CCP00,,,, 64,GP9,GP9,GP9,,,TIM2_PWM1,,,SD0_DAT0,I2S0_DAT0,,,,,TIM0_CC0,,,,
65,GND_TAB,GND_TAB,GND_TAB,,,,,,,,,,,,,,,, 65,GND_TAB,GND_TAB,GND_TAB,,,,,,,,,,,,,,,,
This diff is collapsed.
...@@ -80,7 +80,7 @@ STATIC const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type}; ...@@ -80,7 +80,7 @@ STATIC const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};
DECLARE PUBLIC FUNCTIONS DECLARE PUBLIC FUNCTIONS
******************************************************************************/ ******************************************************************************/
__attribute__ ((section (".boot"))) __attribute__ ((section (".boot")))
void pybrtc_init(void) { void pybrtc_pre_init(void) {
// if the RTC was previously set, leave it alone // if the RTC was previously set, leave it alone
if (MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) { if (MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) {
// fresh reset; configure the RTC Calendar // fresh reset; configure the RTC Calendar
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
extern const mp_obj_type_t pyb_rtc_type; extern const mp_obj_type_t pyb_rtc_type;
extern void pybrtc_init(void); extern void pybrtc_pre_init(void);
extern void pyb_rtc_callback_disable (mp_obj_t self_in); extern void pyb_rtc_callback_disable (mp_obj_t self_in);
extern uint32_t pybrtc_get_seconds (void); extern uint32_t pybrtc_get_seconds (void);
......
...@@ -80,7 +80,7 @@ STATIC mp_obj_t pybsd_unmount (mp_obj_t self_in); ...@@ -80,7 +80,7 @@ STATIC mp_obj_t pybsd_unmount (mp_obj_t self_in);
DEFINE PUBLIC FUNCTIONS DEFINE PUBLIC FUNCTIONS
******************************************************************************/ ******************************************************************************/
__attribute__ ((section (".boot"))) __attribute__ ((section (".boot")))
void pybsd_init0 (void) { void pybsd_pre_init (void) {
// allocate memory for the sd file system // allocate memory for the sd file system
ASSERT ((pybsd_obj.fatfs = mem_Malloc(sizeof(FATFS))) != NULL); ASSERT ((pybsd_obj.fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#if MICROPY_HW_HAS_SDCARD #if MICROPY_HW_HAS_SDCARD
extern const mp_obj_type_t pyb_sd_type; extern const mp_obj_type_t pyb_sd_type;
void pybsd_init0 (void); void pybsd_pre_init (void);
void pybsd_disable (void); void pybsd_disable (void);
bool pybsd_is_mounted (void); bool pybsd_is_mounted (void);
#endif #endif
......
...@@ -128,9 +128,9 @@ soft_reset: ...@@ -128,9 +128,9 @@ soft_reset:
mpexception_init0(); mpexception_init0();
mpcallback_init0(); mpcallback_init0();
pybsleep_init0(); pybsleep_init0();
pin_init0();
mperror_init0(); mperror_init0();
uart_init0(); uart_init0();
pin_init0();
timer_init0(); timer_init0();
readline_init0(); readline_init0();
mod_network_init0(); mod_network_init0();
...@@ -266,7 +266,7 @@ soft_reset_exit: ...@@ -266,7 +266,7 @@ soft_reset_exit:
__attribute__ ((section (".boot"))) __attribute__ ((section (".boot")))
STATIC void mptask_pre_init (void) { STATIC void mptask_pre_init (void) {
#if MICROPY_HW_ENABLE_RTC #if MICROPY_HW_ENABLE_RTC
pybrtc_init(); pybrtc_pre_init();
#endif #endif
// Create the simple link spawn task // Create the simple link spawn task
...@@ -288,7 +288,8 @@ STATIC void mptask_pre_init (void) { ...@@ -288,7 +288,8 @@ STATIC void mptask_pre_init (void) {
modusocket_pre_init(); modusocket_pre_init();
#if MICROPY_HW_HAS_SDCARD #if MICROPY_HW_HAS_SDCARD
pybsd_init0(); // this one allocates memory for the SD file system
pybsd_pre_init();
#endif #endif
CRYPTOHASH_Init(); CRYPTOHASH_Init();
......
...@@ -132,11 +132,10 @@ Q(PULL_NONE) ...@@ -132,11 +132,10 @@ Q(PULL_NONE)
Q(LOW_POWER) Q(LOW_POWER)
Q(MED_POWER) Q(MED_POWER)
Q(HIGH_POWER) Q(HIGH_POWER)
Q(INT_RISING) Q(IRQ_RISING)
Q(INT_FALLING) Q(IRQ_FALLING)
Q(INT_RISING_FALLING) Q(IRQ_LOW_LEVEL)
Q(INT_LOW_LEVEL) Q(IRQ_HIGH_LEVEL)
Q(INT_HIGH_LEVEL)
// for UART class // for UART class
Q(UART) Q(UART)
......
...@@ -65,21 +65,21 @@ Usage Model: ...@@ -65,21 +65,21 @@ Usage Model:
.. only:: port_wipy .. only:: port_wipy
Board pins are identified by their string name:: Board pins are identified by their string id::
g = pyb.Pin('GP9', af=0, mode=pyb.Pin.IN, type=pyb.Pin.STD, strength=pyb.Pin.S2MA) g = pyb.Pin('GP9', mode=pyb.Pin.OUT, pull=pyb.Pin.PULL_NONE, drive=pyb.Pin.MED_POWER, alt=-1)
You can also configure the Pin to generate interrupts. For instance:: You can also configure the Pin to generate interrupts. For instance::
def pincb(pin): def pincb(pin):
print(pin.name()) print(pin.id())
pin_int = pyb.Pin('GP10', af=0, mode=Pin.IN, type=pyb.Pin.STD_PD, strength=pyb.Pin.S2MA) pin_int = pyb.Pin('GP10', mode=Pin.IN, pull=pyb.Pin.PULL_DOWN)
pin_int.callback (mode=pyb.Pin.INT_RISING, handler=pincb) pin_int.irq(mode=pyb.Pin.IRQ_RISING, handler=pincb)
# the callback can be triggered manually # the callback can be triggered manually
pin_int.callback()() pin_int.irq()()
# to disable the callback # to disable the callback
pin_int.callback().disable() pin_int.irq().disable()
Now every time a falling edge is seen on the gpio pin, the callback will be Now every time a falling edge is seen on the gpio pin, the callback will be
executed. Caution: mechanical push buttons have "bounce" and pushing or executed. Caution: mechanical push buttons have "bounce" and pushing or
...@@ -93,19 +93,10 @@ Usage Model: ...@@ -93,19 +93,10 @@ Usage Model:
Constructors Constructors
------------ ------------
.. only:: port_pyboard .. class:: pyb.Pin(id, ...)
.. class:: pyb.Pin(id, ...)
Create a new Pin object associated with the id. If additional arguments are given,
they are used to initialise the pin. See :meth:`pin.init`.
.. only:: port_wipy
.. class:: pyb.Pin(name, ...) Create a new Pin object associated with the id. If additional arguments are given,
they are used to initialise the pin. See :meth:`pin.init`.
Create a new Pin object associated with the name. If additional arguments are given,
they are used to initialise the pin. See :meth:`pin.init`.
.. only:: port_pyboard .. only:: port_pyboard
...@@ -160,36 +151,40 @@ Methods ...@@ -160,36 +151,40 @@ Methods
.. only:: port_wipy .. only:: port_wipy
.. method:: pin.init(af, mode, type, strength) .. method:: pin.init(mode, pull, \*, drive, alt)
Initialise the pin: Initialise the pin:
- ``af`` is the number of the alternate function. Please refer to the
`pinout and alternate functions table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
for the specific alternate functions that each pin supports.
- ``mode`` can be one of: - ``mode`` can be one of:
- ``Pin.OUT`` - no pull up or down resistors. - ``Pin.IN`` - input pin.
- ``Pin.IN`` - enable the pull-up resistor. - ``Pin.OUT`` - output pin in push-pull mode.
- ``Pin.OPEN_DRAIN`` - output pin in open-drain mode.
- ``Pin.ALT`` - pin mapped to an alternate function.
- ``Pin.ALT_OPEN_DRAIN`` - pin mapped to an alternate function in open-drain mode.
- ``type`` can be one of: - ``pull`` can be one of:
- ``Pin.STD`` - push-pull pin. - ``Pin.PULL_NONE`` - no pull up or down resistor.
- ``Pin.STD_PU`` - push-pull pin with pull-up resistor. - ``Pin.PULL_UP`` - pull up resistor enabled.
- ``Pin.STD_PD`` - push-pull pin with pull-down resistor. - ``Pin.PULL_DOWN`` - pull down resitor enabled.
- ``Pin.OD`` - open drain pin.
- ``Pin.OD_PU`` - open drain pin with pull-up resistor.
- ``Pin.OD_PD`` - open drain pin with pull-down resistor.
- ``strength`` can be one of: - ``drive`` can be one of:
- ``Pin.S2MA`` - 2mA drive capability. - ``Pin.LOW_POWER`` - 2mA drive capability.
- ``Pin.S4MA`` - 4mA drive capability. - ``Pin.MED_POWER`` - 4mA drive capability.
- ``Pin.S6MA`` - 6mA drive capability. - ``Pin.HIGH_POWER`` - 6mA drive capability.
- ``alt`` is the number of the alternate function. Please refer to the
`pinout and alternate functions table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
for the specific alternate functions that each pin supports.
Returns: ``None``. Returns: ``None``.
.. method:: pin.id()
Get the pin id.
.. method:: pin.high() .. method:: pin.high()
Set the pin to a high logic level. Set the pin to a high logic level.
...@@ -229,11 +224,9 @@ Methods ...@@ -229,11 +224,9 @@ Methods
will match one of the allowed constants for the mode argument to the init will match one of the allowed constants for the mode argument to the init
function. function.
.. method:: pin.name() .. method:: pin.name()
Get the pin name.
.. only:: port_pyboard Get the pin name.
.. method:: pin.names() .. method:: pin.names()
...@@ -247,44 +240,52 @@ Methods ...@@ -247,44 +240,52 @@ Methods
Get the pin port. Get the pin port.
.. method:: pin.pull() .. method:: pin.pull()
Returns the currently configured pull of the pin. The integer returned Returns the currently configured pull of the pin. The integer returned
will match one of the allowed constants for the pull argument to the init will match one of the allowed constants for the pull argument to the init
function. function.
.. only:: port_wipy .. only:: port_wipy
.. method:: pin([value])
Pin objects are callable. The call method provides a (fast) shortcut to set and get the value of the pin.
See **pin.value** for more details.
.. method:: pin.toggle() .. method:: pin.toggle()
Toggle the value of the pin. Toggle the value of the pin.
.. method:: pin.info() .. method:: pin.mode([mode])
Get or set the pin mode.
Return a 5-tuple with the configuration of the pin: .. method:: pin.pull([pull])
``(name, alternate-function, mode, type, strength)``
.. warning:: Get or set the pin pull.
This method cannot be called within a callback (interrupt-context)
because it needs to allocate memory to return the tuple and memory
allocations are disabled while interrupts are being serviced.
.. method:: pin.callback(\*, mode, priority=1, handler=None, wakes=pyb.Sleep.ACTIVE) .. method:: pin.drive([drive])
Get or set the pin drive strength.
.. method:: pin.irq(\*, trigger, priority=1, handler=None, wake=None)
Create a callback to be triggered when the input level at the pin changes. Create a callback to be triggered when the input level at the pin changes.
- ``mode`` configures the pin level which can generate an interrupt. Possible values are: - ``trigger`` configures the pin level which can generate an interrupt. Possible values are:
- ``Pin.INT_FALLING`` interrupt on falling edge. - ``Pin.IRQ_FALLING`` interrupt on falling edge.
- ``Pin.INT_RISING`` interrupt on rising edge. - ``Pin.IRQ_RISING`` interrupt on rising edge.
- ``Pin.INT_RISING_FALLING`` interrupt on rising and falling edge. - ``Pin.IRQ_LOW_LEVEL`` interrupt on low level.
- ``Pin.INT_LOW_LEVEL`` interrupt on low level. - ``Pin.IRQ_HIGH_LEVEL`` interrupt on high level.
- ``Pin.INT_HIGH_LEVEL`` interrupt on high level.
The values can be *ORed* together, for instance mode=Pin.IRQ_FALLING | Pin.IRQ_RISING
- ``priority`` level of the interrupt. Can take values in the range 1-7. - ``priority`` level of the interrupt. Can take values in the range 1-7.
Higher values represent higher priorities. Higher values represent higher priorities.
- ``handler`` is an optional function to be called when new characters arrive. - ``handler`` is an optional function to be called when new characters arrive.
- ``wake_from`` selects the power mode in which this interrupt can wake up the - ``wakes`` selects the power mode in which this interrupt can wake up the
board. Please note: board. Please note:
- If ``wake_from=pyb.Sleep.ACTIVE`` any pin can wake the board. - If ``wake_from=pyb.Sleep.ACTIVE`` any pin can wake the board.
...@@ -345,68 +346,42 @@ Constants ...@@ -345,68 +346,42 @@ Constants
.. only:: port_wipy .. only:: port_wipy
.. data:: Pin.IN .. data:: Pin.IN
input pin mode
.. data:: Pin.OUT .. data:: Pin.OUT
output pin mode .. data:: Pin.OPEN_DRAIN
.. data:: Pin.STD .. data:: Pin.ALT
push-pull pin type .. data:: Pin.ALT_OPEN_DRAIN
.. data:: Pin.STD_PU Selects the pin mode.
push-pull pin with internall pull-up resistor .. data:: Pin.PULL_NONE
.. data:: Pin.STD_PD .. data:: Pin.PULL_UP
push-pull pin with internall pull-down resistor .. data:: Pin.PULL_DOWN
.. data:: Pin.OD
open-drain pin
.. data:: Pin.OD_PU
open-drain pin with pull-up resistor
.. data:: Pin.OD_PD
open-drain pin with pull-down resistor
.. data:: Pin.INT_FALLING
interrupt on falling edge
.. data:: Pin.INT_RISING
interrupt on rising edge
.. data:: Pin.INT_RISING_FALLING
interrupt on rising and falling edge
.. data:: Pin.INT_LOW_LEVEL
interrupt on low level
.. data:: Pin.INT_HIGH_LEVEL
interrupt on high level
.. data:: Pin.S2MA
2mA drive strength
.. data:: Pin.S4MA
4mA drive strength
.. data:: Pin.S6MA
6mA drive strength Selectes the wether there's pull up/down resistor, or none.
.. data:: Pin.LOW_POWER
.. data:: Pin.MED_POWER
.. data:: Pin.HIGH_POWER
Selects the drive strength.
.. data:: Pin.IRQ_FALLING
.. data:: Pin.IRQ_RISING
.. data:: Pin.IRQ_LOW_LEVEL
.. data:: Pin.IRQ_HIGH_LEVEL
Selects the IRQ trigger type.
.. only:: port_pyboard .. only:: port_pyboard
......
...@@ -28,14 +28,15 @@ See :ref:`pyb.Pin <pyb.Pin>`. :: ...@@ -28,14 +28,15 @@ See :ref:`pyb.Pin <pyb.Pin>`. ::
from pyb import Pin from pyb import Pin
# initialize GP2 in gpio mode (af=0) and make it an output # initialize GP2 in gpio mode (af=0) and make it an output
p_out = Pin('GP2', af=0, mode=Pin.OUT) p_out = Pin('GP2', mode=Pin.OUT)
p_out.high() p_out.high()
p_out.low() p_out.low()
p_out.toggle() p_out.toggle()
p_out(True)
# make GP1 an input with the pull-up enabled # make GP1 an input with the pull-up enabled
p_in = Pin('GP1', af = 0, mode=Pin.IN, type = Pin.STD_PU) p_in = Pin('GP1', mode=Pin.IN, pull = Pin.PULL_UP)
p_in.value() # get value, 0 or 1 p_in() # get value, 0 or 1
Timers Timers
------ ------
......
...@@ -335,7 +335,7 @@ def main(): ...@@ -335,7 +335,7 @@ def main():
test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod', 'pyb', 'pybnative', 'inlineasm') test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod', 'pyb', 'pybnative', 'inlineasm')
elif args.target == 'wipy': elif args.target == 'wipy':
# run WiPy tests # run WiPy tests
test_dirs = ('basics', 'micropython', 'misc', 'extmod') test_dirs = ('basics', 'micropython', 'misc', 'extmod', 'wipy')
else: else:
# run PC tests # run PC tests
test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode', 'extmod', 'unix', 'cmdline') test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode', 'extmod', 'unix', 'cmdline')
......
""" This test need a set of pins which can be set as inputs and have no external
pull up or pull down connected.
"""
from pyb import Pin
import os
machine = os.uname().machine
if 'LaunchPad' in machine:
pin_map = ['GP24', 'GP12', 'GP14', 'GP15', 'GP16', 'GP17', 'GP28', 'GP8', 'GP6', 'GP30', 'GP31', 'GP3', 'GP0', 'GP4', 'GP5']
af_range = range(1, 16)
elif 'WiPy' in machine:
pin_map = ['GP23', 'GP24', 'GP12', 'GP13', 'GP14', 'GP9', 'GP17', 'GP28', 'GP22', 'GP8', 'GP30', 'GP31', 'GP0', 'GP4', 'GP5']
af_range = range(1, 16)
else:
raise Exception('Board not supported!')
def test_noinit():
for p in pin_map:
pin = Pin(p)
pin.value()
def test_pin_read(pull):
# enable the pull resistor on all pins, then read the value
for p in pin_map:
pin = Pin(p, mode=Pin.IN, pull=pull)
# read the pin value
print(pin())
def test_pin_af():
for p in pin_map:
for n in af_range:
Pin(p, mode=Pin.ALT, alt=n)
Pin(p, mode=Pin.ALT_OPEN_DRAIN, alt=n)
# test un-initialized pins
test_noinit()
# test with pull-up and pull-down
test_pin_read(Pin.PULL_UP)
test_pin_read(Pin.PULL_DOWN)
# test all constructor combinations
pin = Pin(pin_map[0])
pin = Pin(pin_map[0], mode=Pin.IN)
pin = Pin(pin_map[0], mode=Pin.OUT)
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.PULL_DOWN)
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OPEN_DRAIN, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_DOWN)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_NONE)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.MED_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, drive=pin.LOW_POWER)
pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_DOWN)
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP)
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP)
test_pin_af() # try the entire af range on all pins
# test pin init and printing
pin = Pin(pin_map[0])
pin.init(mode=Pin.IN)
print(pin)
pin.init(Pin.IN, Pin.PULL_DOWN)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
print(pin)
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_NONE, alt=1)
print(pin)
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_NONE, alt=15)
print(pin)
# test value in OUT mode
pin = Pin(pin_map[0], mode=Pin.OUT)
pin.high() # test high
print(pin.value())
print(pin())
pin.low() # test low
print(pin.value())
print(pin())
pin.toggle() # test toggle
print(pin())
pin.toggle() # test toggle again
print(pin())
# test different value settings
pin(1)
print(pin.value())
pin(0)
print(pin.value())
pin.value(1)
print(pin())
pin.value(0)
print(pin())
# test all getters and setters
pin = Pin(pin_map[0], mode=Pin.OUT)
# mode
print(pin.mode() == Pin.OUT)
pin.mode(Pin.IN)
print(pin.mode() == Pin.IN)
# pull
pin.pull(Pin.PULL_NONE)
print(pin.pull() == Pin.PULL_NONE)
pin.pull(Pin.PULL_DOWN)
print(pin.pull() == Pin.PULL_DOWN)
# drive
pin.drive(Pin.MED_POWER)
print(pin.drive() == Pin.MED_POWER)
pin.drive(Pin.HIGH_POWER)
print(pin.drive() == Pin.HIGH_POWER)
# id
print(pin.id() == pin_map[0])
# all the next ones MUST raise
try:
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.IN) # incorrect drive value
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], mode=Pin.LOW_POWER, pull=Pin.PULL_UP) # incorrect mode value
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.HIGH_POWER) # incorrect pull value
except Exception:
print('Exception')
try:
pin = Pin('A0', Pin.OUT, Pin.PULL_DOWN) # incorrect pin id
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], Pin.IN, Pin.PULL_UP, alt=0) # af specified in GPIO mode
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_UP, alt=7) # af specified in GPIO mode
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP, alt=0) # incorrect af
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=-1) # incorrect af
except Exception:
print('Exception')
try:
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=16) # incorrect af
except Exception:
print('Exception')
try:
pin.mode(Pin.PULL_UP) # incorrect pin mode
except Exception:
print('Exception')
try:
pin.pull(Pin.OUT) # incorrect pull
except Exception:
print('Exception')
try:
pin.drive(Pin.IN) # incorrect drive strength
except Exception:
print('Exception')
try:
pin.id('ABC') # id cannot be set
except Exception:
print('Exception')
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Pin('GP23', mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.IN, pull=Pin.PULL_DOWN, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.LOW_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.HIGH_POWER, alt=-1)
Pin('GP23', mode=Pin.ALT, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=1)
Pin('GP23', mode=Pin.ALT_OPEN_DRAIN, pull=Pin.PULL_NONE, drive=Pin.MED_POWER, alt=15)
1
1
0
0
1
0
1
0
1
0
True
True
True
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment