SRA Board Components
ESP-IDF component for SRA Board
mcpwm_interface.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2021 Society of Robotics and Automation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef MCPWM_INTERFACE_H
26#define MCPWM_INTERFACE_H
27
28#include <stdint.h>
29#include "esp_err.h"
30
35typedef struct motor_t motor_t;
36typedef struct motor_t* motor_handle_t;
37
38struct motor_t {
47 esp_err_t (*enable)(motor_t *motor);
56 esp_err_t (*disable)(motor_t *motor);
66 esp_err_t (*set_speed)(motor_t *motor, uint32_t speed);
75 esp_err_t (*forward)(motor_t *motor);
84 esp_err_t (*backwards)(motor_t *motor);
93 esp_err_t (*brake)(motor_t *motor);
102 esp_err_t (*del)(motor_t *motor);
103};
104
108typedef struct {
109 uint32_t pwma_gpio_num;
110 uint32_t pwmb_gpio_num;
111 uint32_t pwm_freq_hz;
113
117typedef struct {
119 uint32_t resolution_hz;
121
134esp_err_t motor_new_mcpwm_device(const motor_config_t *motor_config, const motor_mcpwm_config_t *mcpwm_config, motor_t** ret_motor);
135
136#endif
esp_err_t motor_new_mcpwm_device(const motor_config_t *motor_config, const motor_mcpwm_config_t *mcpwm_config, motor_t **ret_motor)
Create Motor based on MCPWM peripheral.
Definition: mcpwm_interface.c:110
struct motor_t * motor_handle_t
Definition: mcpwm_interface.h:36
Motor Configuration.
Definition: mcpwm_interface.h:108
uint32_t pwm_freq_hz
Definition: mcpwm_interface.h:111
uint32_t pwma_gpio_num
Definition: mcpwm_interface.h:109
uint32_t pwmb_gpio_num
Definition: mcpwm_interface.h:110
Motor MCPWM specific configuration.
Definition: mcpwm_interface.h:117
int group_id
Definition: mcpwm_interface.h:118
uint32_t resolution_hz
Definition: mcpwm_interface.h:119
Definition: mcpwm_interface.h:38
esp_err_t(* forward)(motor_t *motor)
Set direction of motor to forward.
Definition: mcpwm_interface.h:75
esp_err_t(* brake)(motor_t *motor)
Brake motor.
Definition: mcpwm_interface.h:93
esp_err_t(* disable)(motor_t *motor)
Disable motor.
Definition: mcpwm_interface.h:56
esp_err_t(* enable)(motor_t *motor)
Enable motor.
Definition: mcpwm_interface.h:47
esp_err_t(* backwards)(motor_t *motor)
Set direction of motor to backwards.
Definition: mcpwm_interface.h:84
esp_err_t(* set_speed)(motor_t *motor, uint32_t speed)
Set motor speed.
Definition: mcpwm_interface.h:66
esp_err_t(* del)(motor_t *motor)
Delete motor object.
Definition: mcpwm_interface.h:102