2021-01-20 19:47:18 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MICROPY_INCLUDED_RASPBERRYPI_BINDINGS_RP2PIO_STATEMACHINE_H
|
|
|
|
#define MICROPY_INCLUDED_RASPBERRYPI_BINDINGS_RP2PIO_STATEMACHINE_H
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
|
2022-02-01 11:19:17 -05:00
|
|
|
#include "shared-bindings/digitalio/Pull.h"
|
2021-01-20 19:47:18 -05:00
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
|
|
|
#include "common-hal/rp2pio/StateMachine.h"
|
|
|
|
|
|
|
|
// Type object used in Python. Should be shared between ports.
|
|
|
|
extern const mp_obj_type_t rp2pio_statemachine_type;
|
|
|
|
|
|
|
|
// Construct an underlying SPI object.
|
2021-02-23 18:50:00 -05:00
|
|
|
void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
2021-03-15 09:57:36 -04:00
|
|
|
const uint16_t *program, size_t program_len,
|
2021-01-20 19:47:18 -05:00
|
|
|
size_t frequency,
|
2021-03-15 09:57:36 -04:00
|
|
|
const uint16_t *init, size_t init_len,
|
|
|
|
const mcu_pin_obj_t *first_out_pin, uint8_t out_pin_count, uint32_t initial_out_pin_state, uint32_t initial_out_pin_direction,
|
|
|
|
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, uint32_t pull_pin_up, uint32_t pull_pin_down,
|
|
|
|
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count, uint32_t initial_set_pin_state, uint32_t initial_set_pin_direction,
|
|
|
|
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count, uint32_t initial_sideset_pin_state, uint32_t initial_sideset_pin_direction,
|
2021-12-22 15:00:19 -05:00
|
|
|
bool sideset_enable,
|
2022-02-01 11:19:17 -05:00
|
|
|
const mcu_pin_obj_t *jmp_pin, digitalio_pull_t jmp_pin_pull,
|
2021-04-22 12:47:05 -04:00
|
|
|
uint32_t wait_gpio_mask,
|
2021-01-20 19:47:18 -05:00
|
|
|
bool exclusive_pin_use,
|
|
|
|
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
|
2021-02-23 18:50:00 -05:00
|
|
|
bool wait_for_txstall,
|
2021-08-27 08:18:18 -04:00
|
|
|
bool auto_push, uint8_t push_threshold, bool in_shift_right,
|
2022-02-13 17:38:53 -05:00
|
|
|
bool user_interruptible,
|
|
|
|
int wrap_taget, int wrap);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-02-23 18:50:00 -05:00
|
|
|
void common_hal_rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self);
|
|
|
|
bool common_hal_rp2pio_statemachine_deinited(rp2pio_statemachine_obj_t *self);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-03-04 21:48:24 -05:00
|
|
|
void common_hal_rp2pio_statemachine_never_reset(rp2pio_statemachine_obj_t *self);
|
|
|
|
|
2021-02-23 18:50:00 -05:00
|
|
|
void common_hal_rp2pio_statemachine_restart(rp2pio_statemachine_obj_t *self);
|
|
|
|
void common_hal_rp2pio_statemachine_stop(rp2pio_statemachine_obj_t *self);
|
|
|
|
void common_hal_rp2pio_statemachine_run(rp2pio_statemachine_obj_t *self, const uint16_t *instructions, size_t len);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2023-01-11 18:36:41 -05:00
|
|
|
// Lengths are in bytes.
|
2022-05-06 16:18:59 -04:00
|
|
|
bool common_hal_rp2pio_statemachine_write(rp2pio_statemachine_obj_t *self, const uint8_t *data, size_t len, uint8_t stride_in_bytes, bool swap);
|
|
|
|
bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t *self, const sm_buf_info *once_obj, const sm_buf_info *loop_obj, uint8_t stride_in_bytes, bool swap);
|
2022-04-23 14:09:36 -04:00
|
|
|
bool common_hal_rp2pio_statemachine_stop_background_write(rp2pio_statemachine_obj_t *self);
|
|
|
|
mp_int_t common_hal_rp2pio_statemachine_get_pending(rp2pio_statemachine_obj_t *self);
|
|
|
|
bool common_hal_rp2pio_statemachine_get_writing(rp2pio_statemachine_obj_t *self);
|
2022-05-06 16:18:59 -04:00
|
|
|
bool common_hal_rp2pio_statemachine_readinto(rp2pio_statemachine_obj_t *self, uint8_t *data, size_t len, uint8_t stride_in_bytes, bool swap);
|
2021-02-23 18:50:00 -05:00
|
|
|
bool common_hal_rp2pio_statemachine_write_readinto(rp2pio_statemachine_obj_t *self,
|
2021-03-15 09:57:36 -04:00
|
|
|
const uint8_t *data_out, size_t out_len, uint8_t out_stride_in_bytes,
|
2022-05-06 16:18:59 -04:00
|
|
|
uint8_t *data_in, size_t in_len, uint8_t in_stride_in_bytes, bool swap_out, bool swap_in);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-02-23 18:50:00 -05:00
|
|
|
// Return actual state machine frequency.
|
2021-03-15 09:57:36 -04:00
|
|
|
uint32_t common_hal_rp2pio_statemachine_get_frequency(rp2pio_statemachine_obj_t *self);
|
|
|
|
void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *self, uint32_t frequency);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool common_hal_rp2pio_statemachine_get_rxstall(rp2pio_statemachine_obj_t *self);
|
2021-02-23 18:50:00 -05:00
|
|
|
void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self);
|
2022-05-06 15:42:24 -04:00
|
|
|
bool common_hal_rp2pio_statemachine_get_txstall(rp2pio_statemachine_obj_t *self);
|
|
|
|
void common_hal_rp2pio_statemachine_clear_txstall(rp2pio_statemachine_obj_t *self);
|
2021-03-04 10:29:01 -05:00
|
|
|
size_t common_hal_rp2pio_statemachine_get_in_waiting(rp2pio_statemachine_obj_t *self);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_rp2pio_statemachine_set_interrupt_handler(rp2pio_statemachine_obj_t *self, void (*handler)(void *), void *arg, int mask);
|
2021-03-05 10:00:03 -05:00
|
|
|
|
2021-01-20 19:47:18 -05:00
|
|
|
#endif // MICROPY_INCLUDED_RASPBERRYPI_BINDINGS_RP2PIO_STATEMACHINE_H
|