samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 Robert Hammelrath
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This file initialises provides and checks pin capabilities as required
|
|
|
|
* for USART, I2C, SPI, PWM, ADC
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(MCU_SAMD21)
|
|
|
|
|
2022-09-17 16:27:27 +01:00
|
|
|
typedef struct _machine_pin_obj_t {
|
|
|
|
mp_obj_base_t base;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
uint8_t pin_id;
|
2023-02-03 16:03:31 +00:00
|
|
|
qstr name;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
uint8_t eic;
|
|
|
|
uint8_t adc0;
|
|
|
|
uint8_t sercom1;
|
|
|
|
uint8_t sercom2;
|
|
|
|
uint8_t tcc1;
|
|
|
|
uint8_t tcc2;
|
2022-09-17 16:27:27 +01:00
|
|
|
} machine_pin_obj_t;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
|
|
|
|
#define ALT_FCT_TC 4
|
|
|
|
#define ALT_FCT_TCC1 4
|
|
|
|
#define ALT_FCT_TCC2 5
|
|
|
|
|
|
|
|
#elif defined(MCU_SAMD51)
|
|
|
|
|
2022-09-17 16:27:27 +01:00
|
|
|
typedef struct _machine_pin_obj_t {
|
|
|
|
mp_obj_base_t base;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
uint8_t pin_id;
|
2023-02-03 16:03:31 +00:00
|
|
|
qstr name;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
uint8_t eic;
|
|
|
|
uint8_t adc0;
|
|
|
|
uint8_t adc1;
|
|
|
|
uint8_t sercom1;
|
|
|
|
uint8_t sercom2;
|
|
|
|
uint8_t tc;
|
|
|
|
uint8_t tcc1;
|
|
|
|
uint8_t tcc2;
|
2022-09-17 16:27:27 +01:00
|
|
|
} machine_pin_obj_t;
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
|
|
|
|
#define ALT_FCT_TC 4
|
|
|
|
#define ALT_FCT_TCC1 5
|
|
|
|
#define ALT_FCT_TCC2 6
|
2023-05-24 15:16:40 +01:00
|
|
|
#define ALT_FCT_QSPI 7
|
|
|
|
#define ALT_FCT_CAN1 7
|
|
|
|
#define ALT_FCT_USB 7
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _sercom_pad_config_t {
|
|
|
|
uint8_t alt_fct;
|
|
|
|
uint8_t pad_nr;
|
|
|
|
} sercom_pad_config_t;
|
|
|
|
|
|
|
|
typedef struct _adc_config_t {
|
|
|
|
uint8_t device;
|
|
|
|
uint8_t channel;
|
|
|
|
} adc_config_t;
|
|
|
|
|
|
|
|
typedef struct _pwm_config_t {
|
|
|
|
uint8_t alt_fct;
|
|
|
|
uint8_t device_channel;
|
|
|
|
} pwm_config_t;
|
|
|
|
|
|
|
|
#define ALT_FCT_EIC 0
|
|
|
|
#define ALT_FCT_ADC 1
|
2022-06-07 19:37:44 +01:00
|
|
|
#define ALT_FCT_DAC 1
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
#define ALT_FCT_SERCOM1 2
|
|
|
|
#define ALT_FCT_SERCOM2 3
|
|
|
|
|
2023-02-03 16:03:31 +00:00
|
|
|
extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict;
|
|
|
|
extern const mp_obj_dict_t machine_pin_board_pins_locals_dict;
|
2022-09-17 16:27:27 +01:00
|
|
|
|
samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.
That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C. For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned. Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.
The tables are MCU-specific. It is not required to tell for each board,
which and where each of the above devices is available. That makes addding
boards easy.
Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-06-05 08:26:49 +01:00
|
|
|
sercom_pad_config_t get_sercom_config(int pin_id, uint8_t sercom);
|
|
|
|
adc_config_t get_adc_config(int pin_id, int32_t flag);
|
|
|
|
pwm_config_t get_pwm_config(int pin_id, int wanted_dev, uint8_t used_dev[]);
|
2023-08-14 02:17:18 +01:00
|
|
|
const machine_pin_obj_t *pin_find_by_id(int pin_id);
|
2022-10-09 09:56:29 +01:00
|
|
|
const machine_pin_obj_t *pin_find(mp_obj_t pin);
|