-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch: refactor espFoC to be a motor control solution instead
of a library Signed-off-by: Felipe Neves <[email protected]>
- Loading branch information
Showing
27 changed files
with
459 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/ipm_esp32_appcpu-prefix/src/ipm_esp32_appcpu-build/zephyr) | ||
|
||
if("${BOARD}" STREQUAL "esp32s3_devkitm/esp32s3/procpu") | ||
set(BOARD_REMOTE "esp32s3_devkitm/esp32s3/appcpu") | ||
else() | ||
message(FATAL_ERROR "${BOARD} was not supported for this project yet!") | ||
endif() | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(espfoc) | ||
|
||
set(MOTOR_CONTROL_SRC ${APPLICATION_SOURCE_DIR}/../common) | ||
set(MOTOR_CONTROL_INC ${APPLICATION_SOURCE_DIR}/../common/include/espFoC) | ||
|
||
FILE(GLOB ipc ${MOTOR_CONTROL_SRC}/ipc/*.c) | ||
|
||
set_source_files_properties(${REMOTE_ZEPHYR_DIR}/esp32_appcpu_firmware.c PROPERTIES GENERATED TRUE) | ||
target_sources(app PRIVATE esp_foc_app_core/esp_foc_app.c | ||
esp_foc_app_core/esp_foc_app_shell.c | ||
${ipc} | ||
${REMOTE_ZEPHYR_DIR}/esp32_appcpu_firmware.c) | ||
|
||
target_include_directories(app PRIVATE ${MOTOR_CONTROL_INC}) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add( | ||
espfoc_remote | ||
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/espfoc_motor_core | ||
INSTALL_COMMAND "" | ||
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE} | ||
BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/${KERNEL_BIN_NAME}" | ||
BUILD_ALWAYS True | ||
) | ||
|
||
add_dependencies(app espfoc_remote) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SOC_ESP32S3_PROCPU=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2023 Felipe Neves <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
chosen { | ||
/* | ||
* shared memory reserved for the inter-processor communication | ||
*/ | ||
zephyr,ipc_shm = &shm0; | ||
zephyr,ipc = &ipm0; | ||
}; | ||
}; | ||
|
||
&ipm0 { | ||
status = "okay"; | ||
}; |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(espfoc_remote) | ||
|
||
set(MOTOR_CONTROL_SRC ${APPLICATION_SOURCE_DIR}/../../common) | ||
set(MOTOR_CONTROL_INC ${APPLICATION_SOURCE_DIR}/../../common/include/espFoC) | ||
|
||
FILE(GLOB ipc ${MOTOR_CONTROL_SRC}/ipc/*.c) | ||
FILE(GLOB motor_control ${MOTOR_CONTROL_SRC}/motor_control/*.c) | ||
|
||
target_sources(app PRIVATE esp_foc_motor.c | ||
esp_foc_hardware_if.c | ||
${ipc} | ||
${motor_control}) | ||
|
||
target_include_directories(app PRIVATE ${MOTOR_CONTROL_INC}) |
105 changes: 105 additions & 0 deletions
105
app/espfoc_motor_core/boards/esp32s3_devkitm_appcpu.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2023 Felipe Neves <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <zephyr/dt-bindings/i2c/i2c.h> | ||
#include <zephyr/dt-bindings/pwm/pwm.h> | ||
#include <dt-bindings/pinctrl/esp32s3-pinctrl.h> | ||
|
||
/ { | ||
chosen { | ||
/* | ||
* shared memory reserved for the inter-processor communication | ||
*/ | ||
zephyr,ipc_shm = &shm0; | ||
zephyr,ipc = &ipm0; | ||
}; | ||
|
||
aliases { | ||
motor-pwm-0 = &ledc0; | ||
}; | ||
}; | ||
|
||
&pinctrl { | ||
ledc0_default: ledc0_default { | ||
group1 { | ||
pinmux = <LEDC_CH0_GPIO2>; | ||
output-enable; | ||
}; | ||
group2 { | ||
pinmux = <LEDC_CH1_GPIO3>; | ||
output-enable; | ||
}; | ||
group3 { | ||
pinmux = <LEDC_CH2_GPIO4>; | ||
output-enable; | ||
}; | ||
|
||
}; | ||
|
||
i2c0_default: i2c0_default { | ||
group1 { | ||
pinmux = <I2C0_SDA_GPIO17>, | ||
<I2C0_SCL_GPIO18>; | ||
bias-pull-up; | ||
drive-open-drain; | ||
output-high; | ||
}; | ||
}; | ||
|
||
ledc1_default: ledc1_default { | ||
group1 { | ||
pinmux = <LEDC_CH0_GPIO5>; | ||
output-enable; | ||
}; | ||
group2 { | ||
pinmux = <LEDC_CH1_GPIO6>; | ||
output-enable; | ||
}; | ||
group3 { | ||
pinmux = <LEDC_CH2_GPIO7>; | ||
output-enable; | ||
}; | ||
|
||
}; | ||
|
||
i2c1_default: i2c1_default { | ||
group1 { | ||
pinmux = <I2C1_SDA_GPIO19>, | ||
<I2C1_SCL_GPIO20>; | ||
bias-pull-up; | ||
drive-open-drain; | ||
output-high; | ||
}; | ||
}; | ||
|
||
}; | ||
|
||
&ipm0 { | ||
status = "okay"; | ||
}; | ||
|
||
&ledc0 { | ||
pinctrl-0 = <&ledc0_default>; | ||
pinctrl-names = "default"; | ||
status = "okay"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
channel0@0 { | ||
reg = <0x0>; | ||
timer = <0>; | ||
}; | ||
}; | ||
|
||
&i2c0 { | ||
status = "okay"; | ||
angle_sensor: as5600@0 { | ||
compatible = "ams,as5600"; | ||
status = "okay"; | ||
}; | ||
}; | ||
|
||
&timer3 { | ||
status = "okay"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 Felipe Neves | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/gpio.h> | ||
#include <zephyr/drivers/i2c.h> | ||
#include <zephyr/drivers/pwm.h> | ||
#include <espFoC/motor_control/esp_foc.h> | ||
#include "esp_foc_hardware_if.h" | ||
|
||
static sys_dlist_t motor_if_list; | ||
|
||
struct z_esp_foc_motor_if { | ||
sys_dnode_t link; | ||
struct device *pwm_device; | ||
struct device *i2c_device; | ||
struct device *gpio_device; | ||
struct esp_foc_motor_interface self; | ||
|
||
float current_rotor_deg; | ||
float current_rotor_speed_dps; | ||
}; | ||
|
||
static int reset(struct esp_foc_motor_interface *self) | ||
{ | ||
return 0; | ||
} | ||
|
||
static int enable(struct esp_foc_motor_interface *self) | ||
{ | ||
return 0; | ||
} | ||
|
||
static int set_duty_cycles(struct esp_foc_motor_interface *self, float a, float b, float c) | ||
{ | ||
return 0; | ||
} | ||
|
||
static int get_rotor_angle(struct esp_foc_motor_interface *self, float *angle) | ||
{ | ||
if(!angle) | ||
return -EINVAL; | ||
|
||
return 0; | ||
} | ||
|
||
static int get_rotor_speed_dps(struct esp_foc_motor_interface *self, float *speed_dps) | ||
{ | ||
if(!speed_dps) | ||
return -EINVAL; | ||
|
||
return 0; | ||
} | ||
|
||
static int align_rotor(struct esp_foc_motor_interface *self) | ||
{ | ||
return 0; | ||
} | ||
|
||
static int get_acumulated_angle(struct esp_foc_motor_interface *self, float *angle) | ||
{ | ||
if(!angle) | ||
return -EINVAL; | ||
|
||
return 0; | ||
} | ||
|
||
static int get_encoder_ppr(struct esp_foc_motor_interface *self, float *ppr) | ||
{ | ||
if(!ppr) | ||
return -EINVAL; | ||
|
||
return 0; | ||
} | ||
|
||
static int get_dc_bus_voltage(struct esp_foc_motor_interface *self, float *vdc) | ||
{ | ||
if(!vdc) | ||
return -EINVAL; | ||
|
||
return 0; | ||
} | ||
|
||
static int get_currents(struct esp_foc_motor_interface *self, float *ia, float *ib, float *ic) | ||
{ | ||
if(!ia && !ib && !ic) | ||
return -EINVAL; | ||
|
||
return -ENOTSUP; | ||
} | ||
|
||
static int number_of_shunts(struct esp_foc_motor_interface *self, int *shunts) | ||
{ | ||
if(!shunts) | ||
return -EINVAL; | ||
|
||
return -ENOTSUP; | ||
} | ||
|
||
static int fetch_sensors(struct esp_foc_motor_interface *self) | ||
{ | ||
return 0; | ||
} | ||
|
||
const struct z_esp_foc_motor_if [Z_ESP_FOC_MAX] = { | ||
{ | ||
.reset = reset, | ||
.enable = enable, | ||
.set_duty_cycles = set_duty_cycles, | ||
.get_rotor_angle = get_rotor_angle, | ||
.get_rotor_speed_dps = get_rotor_speed_dps, | ||
.align_rotor = align_rotor, | ||
.get_acumulated_angle = get_acumulated_angle, | ||
.get_encoder_ppr = get_encoder_ppr, | ||
.get_dc_bus_voltage = get_dc_bus_voltage, | ||
.get_currents = get_currents, | ||
.number_of_shunts = number_of_shunts, | ||
.fetch_sensors = fetch_sensors, | ||
}, | ||
{ | ||
.reset = reset, | ||
.enable = enable, | ||
.set_duty_cycles = set_duty_cycles, | ||
.get_rotor_angle = get_rotor_angle, | ||
.get_rotor_speed_dps = get_rotor_speed_dps, | ||
.align_rotor = align_rotor, | ||
.get_acumulated_angle = get_acumulated_angle, | ||
.get_encoder_ppr = get_encoder_ppr, | ||
.get_dc_bus_voltage = get_dc_bus_voltage, | ||
.get_currents = get_currents, | ||
.number_of_shunts = number_of_shunts, | ||
.fetch_sensors = fetch_sensors, | ||
} | ||
} | ||
|
||
struct esp_foc_motor_interface* z_esp_foc_get_interface(enum zephyr_esp_foc_instances instance) | ||
{ | ||
if(instance >= Z_ESP_FOC_MAX) | ||
return NULL; | ||
|
||
return &z_esp_foc_motor_if.self[instance]; | ||
} |
Oops, something went wrong.