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_COMMON_HAL_RP2PIO_STATEMACHINE_H
|
|
|
|
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RP2PIO_STATEMACHINE_H
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
|
2021-03-04 13:28:46 -05:00
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
2021-01-20 19:47:18 -05:00
|
|
|
#include "src/rp2_common/hardware_pio/include/hardware/pio.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
uint32_t pins; // Bitmask of what pins this state machine uses.
|
|
|
|
int state_machine;
|
|
|
|
PIO pio;
|
2021-03-15 09:57:36 -04:00
|
|
|
const uint16_t *init;
|
2021-02-23 18:50:00 -05:00
|
|
|
size_t init_len;
|
|
|
|
uint32_t initial_pin_state;
|
|
|
|
uint32_t initial_pin_direction;
|
2021-03-04 11:03:31 -05:00
|
|
|
uint32_t pull_pin_up;
|
|
|
|
uint32_t pull_pin_down;
|
2021-08-27 08:18:18 -04:00
|
|
|
uint tx_dreq;
|
|
|
|
uint rx_dreq;
|
|
|
|
uint32_t actual_frequency;
|
|
|
|
pio_sm_config sm_config;
|
2021-01-20 19:47:18 -05:00
|
|
|
bool in;
|
|
|
|
bool out;
|
2021-02-23 18:50:00 -05:00
|
|
|
bool wait_for_txstall;
|
2021-01-20 19:47:18 -05:00
|
|
|
bool out_shift_right;
|
|
|
|
bool in_shift_right;
|
2021-08-27 08:18:18 -04:00
|
|
|
bool user_interruptible;
|
2021-02-24 17:58:29 -05:00
|
|
|
uint8_t offset;
|
2022-04-19 16:14:50 -04:00
|
|
|
|
|
|
|
// dma-related items
|
|
|
|
uint8_t buf_obj_idx;
|
|
|
|
const uint8_t *next_buffer;
|
|
|
|
size_t next_size;
|
|
|
|
mp_obj_t buf_objs[2];
|
|
|
|
int continuous_stride_in_bytes;
|
|
|
|
volatile int pending_set_data;
|
2021-01-20 19:47:18 -05:00
|
|
|
} rp2pio_statemachine_obj_t;
|
|
|
|
|
|
|
|
void reset_rp2pio_statemachine(void);
|
|
|
|
|
|
|
|
// Minimal internal version that only fails on pin error (not in use) or full PIO.
|
|
|
|
bool 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,
|
|
|
|
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count,
|
2021-03-04 11:03:31 -05:00
|
|
|
uint32_t pull_pin_up, uint32_t pull_pin_down,
|
2021-03-15 09:57:36 -04:00
|
|
|
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count,
|
|
|
|
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count,
|
2021-02-23 18:50:00 -05:00
|
|
|
uint32_t initial_pin_state, uint32_t initial_pin_direction,
|
2021-07-22 12:39:04 -04:00
|
|
|
const mcu_pin_obj_t *jmp_pin,
|
2021-01-20 19:47:18 -05:00
|
|
|
uint32_t pins_we_use, bool tx_fifo, bool rx_fifo,
|
|
|
|
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
|
2021-02-23 18:50:00 -05:00
|
|
|
bool wait_for_txstall,
|
2021-01-20 19:47:18 -05:00
|
|
|
bool auto_push, uint8_t push_threshold, bool in_shift_right,
|
2021-08-27 08:18:18 -04:00
|
|
|
bool claim_pins,
|
2021-12-22 15:00:19 -05:00
|
|
|
bool interruptible,
|
2022-02-13 17:38:53 -05:00
|
|
|
bool sideset_enable,
|
|
|
|
int wrap_target, int wrap);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
2021-04-22 12:47:05 -04:00
|
|
|
uint8_t rp2pio_statemachine_program_offset(rp2pio_statemachine_obj_t *self);
|
|
|
|
|
2021-01-20 19:47:18 -05:00
|
|
|
void rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self, bool leave_pins);
|
2022-04-19 16:14:50 -04:00
|
|
|
void rp2pio_statemachine_dma_complete(rp2pio_statemachine_obj_t *self, int channel);
|
2021-01-20 19:47:18 -05:00
|
|
|
|
|
|
|
extern const mp_obj_type_t rp2pio_statemachine_type;
|
|
|
|
|
|
|
|
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RP2PIO_STATEMACHINE_H
|