Compare commits

..

12 Commits

Author SHA1 Message Date
cc327ad429 ORDOID-C5: config: add macro PRINT_END
Change-Id: I4040be0773ae009e9a123740a46251b29f3bc6ee
2025-06-24 15:26:30 +09:00
9872a71563 ORDOID-C5: config: change bed screws
Change-Id: I2271cbc4bb74d6f0052bc973b7e40270a63d3dd5
2025-06-24 15:26:30 +09:00
70b845cb00 ORDOID-C5: config: change bed size
Change-Id: Id7a5fa32fd5b49eeed02691426149a3f001b024f
2025-06-24 15:26:30 +09:00
494735229a ORDOID-C5: config: change heater bed PID parameter
Change-Id: I849bd7b8e9579bc7c4f63720d3764aaa07f6bba6
2025-06-24 15:26:30 +09:00
3acafffb69 ODROID-C5: stepper: ignore error "Stepper too far in past"
Change-Id: I10975e37f512ae46b8b474435e809df4e219078f
2025-06-24 15:26:30 +09:00
5f5e89fe50 ODROID-C5: systemd: change default CAN Bus bitrate
Change-Id: I17f4457d2ec83b88391e42831e19019be83c396b
2025-06-24 15:26:30 +09:00
15b2bc24ea ODROID-C5: change package name klipper-mcu to klipper-mcu-odroidc5
Change-Id: I070d6991e60e71c96757fae66f0b5e821cea3f2e
2025-06-24 15:26:30 +09:00
8d4cd86cfe ODROID-C5: analog: fix for ODROID-C5
The iio device file, The read speed of "in_voltage0_input" is very slow. This will adversely affect the stepper motor operation and result in a "Stepper too far in past" error.

Read the value of Voltage0_raw and calculate the ADC voltage directly in the klipper.

Change-Id: Iedb1b5f7fbfedc60d42fc1a28eaa7e49879d6404
2025-06-24 15:26:30 +09:00
3f2d69c139 ODROID-C5: change adc max value and adc file path
ODROID-C5 has two internal 10bit ADCs. However, the value of in_voltage0_raw outputs a difficult number.

So, klipper read "in_voltage0_input", which outputs the actual voltage value, to read the value of ADC.

Change-Id: I32aada4e66e6034823bf66c41fccf178d6ff50d0
2025-06-24 15:26:30 +09:00
182478397b ODROID-C5: systemd: add can systemd network
Change-Id: Ic1c30541e4507c4a92eecea3358e1116b556bf9f
2025-06-24 15:26:30 +09:00
ee34c1d308 ODROID-C5: change baudrate
Baudrates that are too high will not work with the ODROID-C5.

Change-Id: I89c18fa05c3bb10f540c4ab9eec66094e36b8e9d
2025-06-24 15:26:30 +09:00
4d953dd19a ODROID: debian: Add Debian package scripts
- Update klipper to v0.13.0
- Use Python virtual environment

Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
Change-Id: I8847a248fb622a8944e07a1fd858949b93629b86
2025-06-24 15:26:30 +09:00
6 changed files with 45 additions and 137 deletions

6
debian/rules vendored
View File

@@ -2,10 +2,8 @@
define firmware
make distclean
echo CONFIG_MACH_LINUX=y \
> $(shell pwd)/.config
echo CONFIG_MACH_LINUX_ODROIDC5=y | tr -d '[[:space:]]' \
>> $(shell pwd)/.config && make olddefconfig
echo CONFIG_MACH_LINUX=y | tr -d '[[:space:]]' \
> $(shell pwd)/.config && make olddefconfig
TOPDIR=$(shell pwd) make
mkdir -p $(shell pwd)/firmware/LINUX
cp out/klipper.elf $(shell pwd)/firmware/LINUX/klipper_mcu

View File

@@ -16,22 +16,6 @@ config BOARD_DIRECTORY
string
default "linux"
######################################################################
# Board selection
######################################################################
choice
prompt "Board model"
config MACH_LINUX_DEFAULT
bool "DEFAULT"
config MACH_LINUX_ODROIDC5
bool "ODROID-C5"
select MACH_LINUX_ODROID_COMMON
endchoice
config MACH_LINUX_ODROID_COMMON
bool
config CLOCK_FREQ
int
default 50000000

View File

@@ -3,13 +3,10 @@
dirs-y += src/linux src/generic
src-y += linux/main.c linux/timer.c linux/console.c linux/watchdog.c
src-y += linux/pca9685.c linux/spidev.c linux/hard_pwm.c
src-y += linux/pca9685.c linux/spidev.c linux/analog.c linux/hard_pwm.c
src-y += linux/i2c.c linux/gpio.c generic/crc16_ccitt.c generic/alloc.c
src-y += linux/sensor_ds18b20.c
src-$(CONFIG_MACH_LINUX_DEFAULT) += linux/analog.c
src-$(CONFIG_MACH_LINUX_ODROIDC5) += linux/analog_odroidc5.c
CFLAGS_klipper.elf += -lutil -lrt -lpthread
flash: $(OUT)klipper.elf

View File

@@ -13,29 +13,55 @@
#include "internal.h" // report_errno
#include "sched.h" // sched_shutdown
DECL_CONSTANT("ADC_MAX", 4095); // Assume 12bit adc
// ODROID-C5
DECL_CONSTANT("ADC_MAX", 1800);
#define ANALOG_START (1<<12)
DECL_ENUMERATION_RANGE("pin", "analog0", ANALOG_START, 8);
#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw"
// ODROID-C5
#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage0_raw"
#define SCALE_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_scale"
#define OFFSET_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_offset"
struct gpio_adc
gpio_adc_setup(uint32_t pin)
{
char fname[256];
snprintf(fname, sizeof(fname), IIO_PATH, pin-ANALOG_START);
struct gpio_adc g;
int fd;
char buf[64];
int ret;
int fd = open(fname, O_RDONLY|O_CLOEXEC);
fd = open(SCALE_PATH, O_RDONLY);
ret = read(fd, buf, sizeof(buf)-1);
if (ret <= 0) {
goto fail;
}
buf[ret] = '\0';
g.scale = atof(buf) * 1000;
close(fd);
fd = open(OFFSET_PATH, O_RDONLY);
ret = read(fd, buf, sizeof(buf)-1);
if (ret <= 0) {
goto fail;
}
buf[ret] = '\0';
g.offset = atoi(buf);
close(fd);
fd = open(IIO_PATH, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
report_errno("analog open", fd);
goto fail;
}
int ret = set_non_blocking(fd);
ret = set_non_blocking(fd);
if (ret < 0)
goto fail;
return (struct gpio_adc){ .fd = fd };
g.fd = fd;
return g;
fail:
if (fd >= 0)
close(fd);
@@ -52,6 +78,7 @@ uint16_t
gpio_adc_read(struct gpio_adc g)
{
char buf[64];
int voltage;
int ret = pread(g.fd, buf, sizeof(buf)-1, 0);
if (ret <= 0) {
report_errno("analog read", ret);
@@ -59,7 +86,14 @@ gpio_adc_read(struct gpio_adc g)
return 0;
}
buf[ret] = '\0';
return atoi(buf);
voltage = atoi(buf) + g.offset;
voltage = voltage > 0 ? voltage : 0;
voltage = voltage * g.scale;
voltage = voltage < 1800000 ? voltage : 1800000;
voltage /= 1000;
return voltage;
}
void

View File

@@ -1,102 +0,0 @@
// Read analog values from Linux IIO device
//
// Copyright (C) 2017 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <fcntl.h> // open
#include <stdio.h> // snprintf
#include <stdlib.h> // atoi
#include <unistd.h> // read
#include "command.h" // shutdown
#include "gpio.h" // gpio_adc_setup
#include "internal.h" // report_errno
#include "sched.h" // sched_shutdown
// ODROID-C5
DECL_CONSTANT("ADC_MAX", 1800);
#define ANALOG_START (1<<12)
DECL_ENUMERATION_RANGE("pin", "analog0", ANALOG_START, 8);
// ODROID-C5
#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage0_raw"
#define SCALE_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_scale"
#define OFFSET_PATH "/sys/bus/iio/devices/iio:device0/in_voltage_offset"
struct gpio_adc
gpio_adc_setup(uint32_t pin)
{
struct gpio_adc g;
int fd;
char buf[64];
int ret;
fd = open(SCALE_PATH, O_RDONLY);
ret = read(fd, buf, sizeof(buf)-1);
if (ret <= 0) {
goto fail;
}
buf[ret] = '\0';
g.scale = atof(buf) * 1000;
close(fd);
fd = open(OFFSET_PATH, O_RDONLY);
ret = read(fd, buf, sizeof(buf)-1);
if (ret <= 0) {
goto fail;
}
buf[ret] = '\0';
g.offset = atoi(buf);
close(fd);
fd = open(IIO_PATH, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
report_errno("analog open", fd);
goto fail;
}
ret = set_non_blocking(fd);
if (ret < 0)
goto fail;
g.fd = fd;
return g;
fail:
if (fd >= 0)
close(fd);
shutdown("Unable to open adc device");
}
uint32_t
gpio_adc_sample(struct gpio_adc g)
{
return 0;
}
uint16_t
gpio_adc_read(struct gpio_adc g)
{
char buf[64];
int voltage;
int ret = pread(g.fd, buf, sizeof(buf)-1, 0);
if (ret <= 0) {
report_errno("analog read", ret);
try_shutdown("Error on analog read");
return 0;
}
buf[ret] = '\0';
voltage = atoi(buf) + g.offset;
voltage = voltage > 0 ? voltage : 0;
voltage = voltage * g.scale;
voltage = voltage < 1800000 ? voltage : 1800000;
voltage /= 1000;
return voltage;
}
void
gpio_adc_cancel_sample(struct gpio_adc g)
{
}

View File

@@ -1,7 +1,6 @@
#ifndef __LINUX_GPIO_H
#define __LINUX_GPIO_H
#include "autoconf.h" // CONFIG_MACH_LINUX_*
#include <stdint.h> // uint8_t
struct gpio_out {
@@ -21,10 +20,8 @@ void gpio_in_reset(struct gpio_in g, int8_t pull_up);
uint8_t gpio_in_read(struct gpio_in g);
struct gpio_adc {
#ifdef CONFIG_MACH_LINUX_ODROIDC5
int scale;
int offset;
#endif
int fd;
};
struct gpio_adc gpio_adc_setup(uint32_t pin);