Skip to content

Commit

Permalink
docs: Add more documentation for the CC3200 in the pyb module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Campora committed Jun 16, 2015
1 parent cdfa11f commit ea2cc2b
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 240 deletions.
36 changes: 25 additions & 11 deletions cc3200/mods/pybtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,9 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
/// Initialise the timer. Initialisation must give the desired mode
/// and an optional timer width
///
/// tim.init(mode=Timer.ONE_SHOT, width=32) # one shot mode
/// tim.init(mode=Timer.PERIODIC) # configure in free running periodic mode
/// tim.init(mode=Timer.ONE_SHOT, width=16) # one shot mode splitted into two 16-bit independent timers
/// split into two 16-bit independent timers
///
/// Keyword arguments:
///
Expand All @@ -326,7 +327,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, },
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 32} },
{ MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} },
};

// parse args
Expand Down Expand Up @@ -405,7 +406,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);

/// \method channel(channel, *, freq, polarity, duty_cycle)
/// \method channel(channel, *, freq, period, polarity, duty_cycle)
/// Initialise the timer channel. Initialization requires at least a frequency param. With no
/// extra params given besides the channel id, the channel is returned with the previous configuration
/// os 'None', if it hasn't been initialized before.
Expand Down Expand Up @@ -735,7 +736,7 @@ STATIC mp_obj_t pyb_timer_channel_duty_cycle(mp_uint_t n_args, const mp_obj_t *a
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle);

/// \method callback(handler, value, priority)
/// \method callback(handler, priority, value)
/// create a callback object associated with the timer channel
STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[mpcallback_INIT_NUM_ARGS];
Expand All @@ -753,10 +754,21 @@ STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *po
goto invalid_args;
}

uint32_t _config = (ch->channel == TIMER_B) ? ((ch->timer->config & TIMER_B) >> 8) : (ch->timer->config & TIMER_A);

// validate and set the value if we are in edge count mode
if (_config == TIMER_CFG_A_CAP_COUNT) {
uint32_t c_value = args[3].u_int;
if (!c_value || c_value > 0xFFFF) {
// zero or exceeds the maximum value of a 16-bit timer
goto invalid_args;
}
MAP_TimerMatchSet(ch->timer->timer, ch->channel, c_value);
}

// disable the callback first
pyb_timer_channel_callback_disable(ch);

uint32_t _config = (ch->channel == TIMER_B) ? ((ch->timer->config & TIMER_B) >> 8) : (ch->timer->config & TIMER_A);
uint8_t shift = (ch->channel == TIMER_B) ? 8 : 0;
switch (_config) {
case TIMER_CFG_A_ONE_SHOT:
Expand All @@ -778,13 +790,9 @@ STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *po
default:
break;
}
// special case for a 32-bit timer
if (ch->channel == (TIMER_A | TIMER_B)) {
// again a special case for the pwm match interrupt
if (_config == TIMER_CFG_A_PWM) {
ch->timer->intflags |= TIMER_TIMB_MATCH;
} else {
ch->timer->intflags |= (ch->timer->intflags << 8);
}
ch->timer->intflags |= (ch->timer->intflags << 8);
}

void (*pfnHandler)(void);
Expand Down Expand Up @@ -835,6 +843,12 @@ STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *po
// create the callback
_callback = mpcallback_new (ch, args[1].u_obj, &pyb_timer_channel_cb_methods);

// reload the timer
uint32_t period_c;
uint32_t match;
compute_prescaler_period_and_match_value(ch, &period_c, &match);
MAP_TimerLoadSet(ch->timer->timer, ch->channel, period_c);

// enable the callback before returning
pyb_timer_channel_callback_enable(ch);
}
Expand Down
8 changes: 4 additions & 4 deletions docs/library/pyb.Pin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ Methods
Return a 5-tuple with the configuration of the pin:
``(name, alternate-function, mode, type, strength)``

.. method:: pin.callback(mode, priority=1, handler=None, wakes=pyb.Sleep.ACTIVE)
.. method:: pin.callback(\*, mode, priority=1, handler=None, wakes=pyb.Sleep.ACTIVE)

Create a callback to be triggered when data is received on the UART.
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:

Expand All @@ -286,8 +286,8 @@ Methods
of this pins can be enabled as a wake source at the same time, so, only
the last enabled pin as a ``pyb.Sleep.SUSPENDED`` wake source will have effect.
- If ``wakes=pyb.Sleep.SUSPENDED`` pins ``GPIO2``, ``GPIO4``, ``GPIO10``,
``GPIO11``, GPIO17`` and ``GPIO24`` can wake the board. In this case all this 6
pins can be enabled as a ``pyb.Sleep.HIBERNATE`` wake source at the same time.
``GPIO11``, ``GPIO17`` and ``GPIO24`` can wake the board. In this case all of the
6 pins can be enabled as a ``pyb.Sleep.HIBERNATE`` wake source at the same time.
- Values can be ORed to make a pin generate interrupts in more than one power
mode.

Expand Down
20 changes: 15 additions & 5 deletions docs/library/pyb.RTC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,23 @@ Methods
date and time. With 1 argument (being an 8-tuple) it sets the date
and time.

The 8-tuple has the following format:
.. only:: port_pyboard

(year, month, day, weekday, hours, minutes, seconds, subseconds)

``weekday`` is 1-7 for Monday through Sunday.
The 8-tuple has the following format:

(year, month, day, weekday, hours, minutes, seconds, subseconds)

``weekday`` is 1-7 for Monday through Sunday.

``subseconds`` counts down from 255 to 0

.. only:: port_wipy

``subseconds`` counts down from 255 to 0
The 8-tuple has the following format:

``(year, month, day, weekday, hours, minutes, seconds, milliseconds)``

``weekday`` is 0-6 for Monday through Sunday.

.. only:: port_pyboard

Expand Down
2 changes: 1 addition & 1 deletion docs/library/pyb.SD.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Example usage::

# data, clk and cmd pins must be passed along with
# their respective alternate functions
sd = pyb.SD('GPIO15', 8, 'GPIO16', 8, 'GPIO17', 8)
sd = pyb.SD('GPIO15', 8, 'GPIO10', 6, 'GPIO11', 6)
sd.enable() # enable and mount the SD card
sd.disable() # disable and unmount it

Expand Down
Loading

0 comments on commit ea2cc2b

Please sign in to comment.