forked from LinuxCNC/linuxcnc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unified HM2 SPI driver supporting RPI3, RPi4, RPi5 and spidev.
- Loading branch information
Showing
14 changed files
with
3,675 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* This is a component for RaspberryPi and other boards for linuxcnc. | ||
* Copyright (c) 2024 B.Stultiens <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program; if not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef HAL_DTCBOARDS_H | ||
#define HAL_DTCBOARDS_H | ||
|
||
/* | ||
* Info about the hardware platform, see: | ||
* https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#best-practices-for-revision-code-usage | ||
* https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#check-raspberry-pi-model-and-cpu-across-distributions | ||
* | ||
* Reading /proc/device-tree/compatible should contain the relevant | ||
* information. We should get a buffer containing a string-list like: | ||
* "raspberrypi,5-model-b\0brcm,bcm2712\0" | ||
* And yes, it has embedded NULs. | ||
* | ||
* The idea is to match one of the strings to assign the correct driver for the | ||
* specific board. | ||
*/ | ||
#define DTC_BOARD_MAKE_RPI "raspberrypi" | ||
|
||
#define DTC_BOARD_MODEL_5CM "5-compute-module" | ||
#define DTC_BOARD_MODEL_5B "5-model-b" | ||
#define DTC_BOARD_MODEL_4CM "4-compute-module" | ||
#define DTC_BOARD_MODEL_4B "4-model-b" | ||
#define DTC_BOARD_MODEL_3CM "3-compute-module" | ||
#define DTC_BOARD_MODEL_3BP "3-model-b-plus" | ||
#define DTC_BOARD_MODEL_3AP "3-model-a-plus" | ||
#define DTC_BOARD_MODEL_3B "3-model-b" | ||
#define DTC_BOARD_MODEL_2B "2-model-b" | ||
#define DTC_BOARD_MODEL_CM "compute-module" | ||
#define DTC_BOARD_MODEL_BP "model-b-plus" | ||
#define DTC_BOARD_MODEL_AP "model-a-plus" | ||
#define DTC_BOARD_MODEL_BR2 "model-b-rev2" | ||
#define DTC_BOARD_MODEL_B "model-b" | ||
#define DTC_BOARD_MODEL_A "model-a" | ||
#define DTC_BOARD_MODEL_ZERO_2W "model-zero-2-w" | ||
#define DTC_BOARD_MODEL_ZERO_W "model-zero-w" | ||
#define DTC_BOARD_MODEL_ZERO "model-zero" | ||
|
||
#define DTC_SOC_MAKE_BRCM "brcm" | ||
|
||
#define DTC_SOC_MODEL_BCM2712 "bcm2712" | ||
#define DTC_SOC_MODEL_BCM2711 "bcm2711" | ||
#define DTC_SOC_MODEL_BCM2837 "bcm2837" | ||
#define DTC_SOC_MODEL_BCM2836 "bcm2836" | ||
#define DTC_SOC_MODEL_BCM2835 "bcm2835" | ||
|
||
/* The device-tree compatible strings for the boards */ | ||
#define DTC_RPI_SOC_BCM2712 DTC_SOC_MAKE_RPI "," DTC_SOC_MODEL_BCM2712 | ||
#define DTC_RPI_MODEL_5CM DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_5CM | ||
#define DTC_RPI_MODEL_5B DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_5B | ||
|
||
#define DTC_RPI_SOC_BCM2711 DTC_SOC_MAKE_RPI "," DTC_SOC_MODEL_BCM2711 | ||
#define DTC_RPI_MODEL_4CM DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_4CM | ||
#define DTC_RPI_MODEL_4B DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_4B | ||
|
||
#define DTC_RPI_SOC_BCM2837 DTC_SOC_MAKE_BRCM "," DTC_SOC_MODEL_BCM2837 | ||
#define DTC_RPI_MODEL_3CM DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_3CM | ||
#define DTC_RPI_MODEL_3BP DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_3BP | ||
#define DTC_RPI_MODEL_3AP DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_3AP | ||
#define DTC_RPI_MODEL_3B DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_3B | ||
#define DTC_RPI_MODEL_ZERO_2W DTC_BOARD_MAKE_RPI "," DTC_BOARD_MODEL_ZERO_2W | ||
|
||
/* Older than a RPi3 (bcm2836 and bcm2835) is probably not a good idea to use. */ | ||
|
||
#endif | ||
// vim: ts=4 |
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,62 @@ | ||
/* | ||
* This is a component for hostmot2 board drivers | ||
* Copyright (c) 2013,2014,2020,2024 Michael Geszkiewicz <[email protected]>, | ||
* Jeff Epler <[email protected]> | ||
* B.Stultiens <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program; if not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <errno.h> | ||
#include <sys/wait.h> | ||
|
||
#include <rtapi.h> | ||
|
||
int shell(char *command) | ||
{ | ||
char *const argv[] = {"sh", "-c", command, NULL}; | ||
pid_t pid; | ||
int res = rtapi_spawn_as_root(&pid, "/bin/sh", NULL, NULL, argv, environ); | ||
if(res < 0) | ||
perror("rtapi_spawn_as_root"); | ||
int status; | ||
waitpid(pid, &status, 0); | ||
if(WIFEXITED(status)) | ||
return WEXITSTATUS(status); | ||
else if(WIFSTOPPED(status)) | ||
return WTERMSIG(status)+128; | ||
return status; | ||
} | ||
|
||
int eshellf(const char *errpfx, const char *fmt, ...) | ||
{ | ||
char commandbuf[1024]; | ||
va_list ap; | ||
va_start(ap, fmt); | ||
vsnprintf(commandbuf, sizeof(commandbuf), fmt, ap); | ||
va_end(ap); | ||
|
||
int res = shell(commandbuf); | ||
if(res == EXIT_SUCCESS) | ||
return 0; | ||
|
||
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: Failed to execute '%s'\n", errpfx ? errpfx : "eshellf()", commandbuf); | ||
return -EINVAL; | ||
} | ||
|
||
/* vim: ts=4 | ||
*/ |
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,28 @@ | ||
/* | ||
* This is a component for hostmot2 board drivers | ||
* Copyright (c) 2013,2014,2020,2024 Michael Geszkiewicz <[email protected]>, | ||
* Jeff Epler <[email protected]> | ||
* B.Stultiens <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program; if not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef HAL_HM2_ESHELLF_H | ||
#define HAL_HM2_ESHELLF_H | ||
|
||
int shell(char *command); | ||
int eshellf(const char *errpfx, const char *fmt, ...); | ||
|
||
#endif | ||
/* vim: ts=4 | ||
*/ |
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
Oops, something went wrong.