Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Azarton C1 T20X JXF23 RTL8189FS_SDIO NOR_16M done
Azarton C1 T31X GC2053 RTL8189FS_SDIO NOR_16M done
Babysense See HD IP206 SSC333 GC2053 RTL8188FU_USB NOR_16M done
Baolian 11R6W25-HX20Y HI3518EV200 JXH65 MT7601U_USB NOR_8M testing, zoom/focus lens (OpenIPC/firmware#2675)
Botslab C213 T23N SC3332 ATBM6012B_USB NOR_8M **INIT** - frozen
Botslab C213 T23N SC3332 ATBM6012B_USB NOR_8M testing, pan/tilt-ok (TMI8152 SPI), ircut-ok, wifi-ok, eth-ok, video-ok, audio-ok, sd-ok (SC3332 driver: OpenIPC/openingenic sc3332-t23)
CCDCAM IM50Q01 SSC377QE IMX335 - NOR_16M done
ChinaTelecom DS-YTJ5301 SSC30KD GC2053 RTL8188FU_USB NOR_16M video-ok, wifi-no, motors-no
ChinaTelecom Y4H-50 T31L ? ? NOR_16M new
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Architecture
BR2_mipsel=y
BR2_mips_xburst=y
# BR2_MIPS_SOFT_FLOAT is not set
BR2_MIPS_FP32_MODE_32=y

# Toolchain
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="https://github.com/openipc/firmware/releases/download/toolchain/toolchain.ingenic-t31.tgz"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="mipsel-openipc-linux-musl"
BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y

# Kernel
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="https://github.com/openipc/linux/archive/ingenic-t23.tar.gz"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(EXTERNAL_VENDOR)/board/$(OPENIPC_SOC_FAMILY)/t23.generic.config"
BR2_LINUX_KERNEL_LZMA=y

# Filesystem
BR2_PACKAGE_BUSYBOX_CONFIG="$(BR2_EXTERNAL)/package/busybox/busybox.config"
BR2_PACKAGE_UBOOT_TOOLS=y
BR2_PACKAGE_ZLIB=y
# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set
BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y
BR2_PACKAGE_WIREGUARD_TOOLS=y
BR2_PACKAGE_WIRELESS_TOOLS=y
BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
BR2_PACKAGE_WPA_SUPPLICANT_PASSPHRASE=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_SQUASHFS=y
BR2_TARGET_ROOTFS_SQUASHFS4_XZ=y

# OpenIPC
BR2_OPENIPC_SOC_VENDOR="ingenic"
BR2_OPENIPC_SOC_MODEL="t23"
BR2_OPENIPC_SOC_FAMILY="t23"
BR2_OPENIPC_VARIANT="lite"
BR2_OPENIPC_FLASH_SIZE="8"

# Packages
BR2_PACKAGE_DROPBEAR_OPENIPC=y
BR2_PACKAGE_INGENIC_OSDRV_T23=y
BR2_PACKAGE_IPCTOOL=y
BR2_PACKAGE_LIBCURL_OPENIPC=y
BR2_PACKAGE_LIBCURL_OPENIPC_CURL=y
# BR2_PACKAGE_LIBCURL_OPENIPC_PROXY_SUPPORT is not set
# BR2_PACKAGE_LIBCURL_OPENIPC_COOKIES_SUPPORT is not set
# BR2_PACKAGE_LIBCURL_OPENIPC_EXTRA_PROTOCOLS_FEATURES is not set
BR2_PACKAGE_LIBEVENT_OPENIPC=y
BR2_PACKAGE_LIBOGG_OPENIPC=y
BR2_PACKAGE_MAJESTIC_FONTS=y
BR2_PACKAGE_MAJESTIC_WEBUI=y
BR2_PACKAGE_MAJESTIC=y
BR2_PACKAGE_MBEDTLS_OPENIPC=y
BR2_PACKAGE_OPUS_OPENIPC=y
BR2_PACKAGE_OPUS_OPENIPC_FIXED_POINT=y
BR2_PACKAGE_VTUND_OPENIPC=y
BR2_PACKAGE_YAML_CLI=y
BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_GENERAL_PATH)/scripts/post-image-split.sh"

# Botslab C213 (T23N + SC3332 + ATBM6012B USB + TMI8152 SPI)
BR2_PACKAGE_ATBM603X_COMB_OPENIPC=y
BR2_PACKAGE_MOTORS=y
BR2_PACKAGE_TMI8152_C213=y
BR2_PACKAGE_MAJESTIC_WEBUI_PTZ=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh
#
# Botslab C213: TMI8152 (SPI motor + IR-cut driver) and helper daemons.
#
# fw_printenv knobs (all optional):
# motor_hmaxstep pan range, steps (default 8000 = stock 500 counts x 16)
# motor_vmaxstep tilt range, steps (default 3200 = stock 200 counts x 16)
# motor_xcenter pan home, steps (default 4000 = stock 250 from the stop)
# motor_ycenter tilt home, steps (default 960 = stock 60 from the low stop)
# motor_invert "x", "y" or "xy" (default none)
# motor_xch/ych TMI channel of pan / tilt (default 0 / 1, as stock)
# ircut_day value for day: 0 or 1 (default 1)
# motor_unit WebUI pad step, steps (default 40, see /usr/bin/motor)
# motor_speed WebUI pad speed, 1..900 (default 900)

getenv() { fw_printenv -n "$1" 2>/dev/null; }

# WebUI PTZ: the "motor" backend runs /usr/bin/motor <profile> <h> <v>.
# Set once, so a camera configured before this existed gets it too.
ptz_env() {
[ -n "$(getenv ptz_control)" ] || fw_setenv ptz_control motor
[ -n "$(getenv ptz_profile)" ] || fw_setenv ptz_profile c213
[ -n "$(getenv ptz_caps)" ] || fw_setenv ptz_caps "pan tilt"
}

# majestic used to drive GPIO63 as the speaker pin and so switched the TMI
# power stage off; the amplifier is GPIO53.
speaker_fix() {
[ "$(cli -g .audio.speakerPin 2>/dev/null)" = 63 ] && cli -s .audio.speakerPin 53
gpio set 63 >/dev/null
}

start() {
ptz_env
speaker_fix
modprobe tmi8152_spi_dev || {
echo "c213: TMI8152 not found on SPI0" | logger -s -t c213
return 1
}

inv=$(getenv motor_invert)
modprobe tmi8152_motor \
hmaxstep="$(getenv motor_hmaxstep || echo 8000)" \
vmaxstep="$(getenv motor_vmaxstep || echo 3200)" \
center_x_override="$(getenv motor_xcenter || echo 4000)" \
center_y_override="$(getenv motor_ycenter || echo 960)" \
invert_x="$(case "$inv" in *x*) echo 1;; *) echo 0;; esac)" \
invert_y="$(case "$inv" in *y*) echo 1;; *) echo 0;; esac)" \
x_channel="$(getenv motor_xch || echo 0)" \
y_channel="$(getenv motor_ych || echo 1)"

# Homing: the driver waits for MOTOR_RESET with zero limits.
(ingenic-motor -r >/dev/null 2>&1 &)

start-stop-daemon -S -b -m -p /var/run/ircut-sync.pid -x /usr/sbin/ircut-sync
start-stop-daemon -S -b -m -p /var/run/resetd.pid -x /usr/sbin/resetd.sh
}

stop() {
start-stop-daemon -K -q -p /var/run/ircut-sync.pid
start-stop-daemon -K -q -p /var/run/resetd.pid
# Shell scripts: the pid file can miss them, the process name does not.
killall -q ircut-sync resetd.sh
rm -f /var/run/ircut-sync.pid /var/run/resetd.pid
}

case "$1" in
start) start ;;
stop) stop ;;
restart) stop; start ;;
*) echo "Usage: $0 {start|stop|restart}"; exit 1 ;;
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Botslab C213: the sensor reset is PA17 (stock sensor_sc3332_t23.ko default).
# PA18, the T23 default, is the reset button here: neither the sensor driver
# nor sinfo's probe may drive it.
options sensor_sc3332_t23 reset_gpio=17
options sinfo reset_gpio=17
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sensor:
name: sc3332
address: 0x30
width: 2304
height: 1296
bus: i2c
37 changes: 37 additions & 0 deletions devices/t23_lite_botslab-c213/general/overlay/usr/bin/motor
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
#
# WebUI "motor" PTZ backend for Botslab C213 (TMI8152 via /dev/motor).
#
# motor <profile> <h> <v>
#
# j/ptz.cgi calls this with h, v in -99..99; the pad sends +-5 per press and
# 0 0 for "centre". Each unit is motor_unit steps (fw_setenv motor_unit N,
# default 40: 2.5 counts of the stock 500-count pan).
#
# fw_setenv ptz_invert "x" | "y" | "xy" | "none" - flip the WebUI arrows
# (default "x": the pad's pan runs opposite to the driver's +/- on C213).
# Only the pad is flipped; homing and the driver's own directions stay as stock.

[ $# -ge 3 ] || { echo "usage: motor <profile> <h> <v>" >&2; exit 2; }
h=$2
v=$3
case "$h" in ''|*[!0-9-]*) echo "bad h: $h" >&2; exit 2 ;; esac
case "$v" in ''|*[!0-9-]*) echo "bad v: $v" >&2; exit 2 ;; esac

[ -c /dev/motor ] || { echo "No /dev/motor: tmi8152_motor is not loaded." >&2; exit 1; }

unit=$(fw_printenv -n motor_unit 2>/dev/null)
case "$unit" in ''|*[!0-9]*) unit=40 ;; esac
speed=$(fw_printenv -n motor_speed 2>/dev/null)
case "$speed" in ''|*[!0-9]*) speed=900 ;; esac

if [ "$h" -eq 0 ] && [ "$v" -eq 0 ]; then
# Centre: the driver's home (center_x/y_override, stock 250 / 60 counts).
exec ingenic-motor -d b
fi

inv=$(fw_printenv -n ptz_invert 2>/dev/null) || inv=x
case "$inv" in *x*) h=$((-h)) ;; esac
case "$inv" in *y*) v=$((-v)) ;; esac

exec ingenic-motor -d g -x $((h * unit)) -y $((v * unit)) -s "$speed"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
#
# The C213 IR-cut filter hangs off TMI8152 channel 5 (SPI), which majestic
# cannot drive: it only pulses GPIO irCutPin1/2. Follow majestic's own
# day/night state instead (night_enabled in /metrics), so the automatic switch
# and the WebUI's Day/Night buttons (/night/on, /night/off, /night/toggle)
# both move the filter. If /metrics cannot be read, fall back to the IR
# illuminator pin majestic switches with night mode (backlightPin=49).
#
# fw_setenv ircut_day 0|1 - value written for day (default 1)
# fw_setenv ir_led_on 0|1 - level of GPIO49 that means "IR LEDs on" (default 1)

# Kernel-side parameter first: write() on the char device cannot read the
# user buffer on this kernel ("Error copying data from user").
DEV=/sys/module/tmi8152_spi_dev/parameters/ircut
[ -w "$DEV" ] || DEV=/dev/tmi8152_ir_cut
PIN=49
DAY=$(fw_printenv -n ircut_day 2>/dev/null || echo 1)
LED_ON=$(fw_printenv -n ir_led_on 2>/dev/null || echo 1)
NIGHT=$((1 - DAY))
last=""

[ -e "$DEV" ] || { echo "ircut-sync: no $DEV" | logger -t ircut; exit 1; }

# 1 night, 0 day, empty when unknown.
night_state() {
local m
m=$(curl -s -m 2 http://127.0.0.1/metrics 2>/dev/null | sed -n 's/^night_enabled \([01]\)$/\1/p')
if [ -n "$m" ]; then
echo "$m"
return
fi
m=$(cat /sys/class/gpio/gpio$PIN/value 2>/dev/null) || return
[ "$m" = "$LED_ON" ] && echo 1 || echo 0
}

# Day position at start, like the stock app.
printf %s "$DAY" > "$DEV"
last=$DAY

while sleep 2; do
n=$(night_state)
[ -n "$n" ] || continue
if [ "$n" = 1 ]; then want=$NIGHT; else want=$DAY; fi
if [ "$want" != "$last" ]; then
printf %s "$want" > "$DEV" && last=$want
logger -t ircut "filter -> $([ "$want" = "$DAY" ] && echo day || echo night)"
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

if [ -e /usr/share/openipc/gpio.conf ]; then
. /usr/share/openipc/gpio.conf
fi


[ -z $button ] && echo "GPIO pin for resetd is not set" | logger -t resetd && exit

# Counter for button press until reset
count=0

# prepare the pin
if [ ! -d /sys/class/gpio/gpio${button} ]; then
echo "${button}" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio${button}/direction
fi

# A pin that cannot be read (e.g. taken by a driver) must not count as pressed.
if [ ! -r /sys/class/gpio/gpio${button}/value ]; then
echo "GPIO${button} is not available, resetd disabled" | logger -t resetd
exit 1
fi

# continuously monitor current value of reset switch
while [ true ]; do
# On the C213 the button pin (PA18) is the T23 default sensor reset:
# tx-isp-t23 (vendor, closed) makes it an output driven high when it
# probes, behind gpiolib's back (sysfs still says "in"), and it then
# reads 1 for ever. Make it an input again on every pass.
echo in > /sys/class/gpio/gpio${button}/direction 2>/dev/null
v=; read -r v 2>/dev/null < /sys/class/gpio/gpio${button}/value
if [ "$v" != 0 ]; then
count=0
else
count=$((count+1))
# 20 counts =~ 5 seconds @ 0.25 sleep intervals
if [ $count -eq 20 ]; then
#echo 'SET WIFI' | logger -t resetd
#fw_setenv wlanssid WIFI
#fw_setenv wlanpass 12345678
for a in $(seq 10) ; do (gpio toggle ${led1} ; sleep 0.3 ; gpio toggle ${led1} ; sleep 0.3) ; done >/dev/null 2>&1
echo 'RESETTING FIRMWARE' | logger -t resetd
firstboot
fi
fi
# Shell builtins only (echo, read): nothing forks in the loop but sleep.
sleep 0.25
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# Botslab C213: one-time settings on first boot (run by S30customizer).
#

fw_setenv upgrade 'https://github.com/OpenIPC/builder/releases/download/latest/t23_lite_botslab-c213-nor.tgz'

# SD card detect is PB19 (51). The loader default 59 (PB27) is an SSI0 pin
# used by the TMI8152 motor driver and must not be claimed by jzmmc.
fw_setenv gpio_mmc 51

# Wi-Fi: ATBM6012B combo over USB, atbm603x driver (stock: atbm603x_wifi_usb wifi_bt_comb=1)
fw_setenv wlandev atbm603x-generic-usb
#fw_setenv wlanssid Router
#fw_setenv wlanpass 12345678

# Memory split for the OpenIPC U-Boot (the stock U-Boot takes it from bootargs).
# Stock used 19.5M rmem with ISP direct_mode; majestic needs 24M for 2304x1296.
fw_setenv osmem 40M@0x0
fw_setenv rmem 24M@0x2800000

# Majestic
cli -s .video0.codec h264
# Image comes out upside down with the stock sensor driver (shvflip=1);
# the stock app turned it in the ISP. Checked on the camera: both flags.
cli -s .image.flip true
cli -s .image.mirror true
# Sensor gives 2304x1296, but the T23 H.264 encoder rejects a 1296-line NV12
# buffer ("invalidate input nal buffer align"): height must be a multiple of 32.
cli -s .video0.size 2304x1280
cli -s .nightMode.lightMonitor true
cli -s .nightMode.backlightPin 49
cli -s .nightMode.monitorDelay 5
cli -s .osd.enabled true
cli -s .audio.enabled true
cli -s .audio.codec aac
cli -s .audio.srate 48000
cli -s .audio.volume 90
cli -s .audio.gain 26
cli -s .audio.outputEnabled true
cli -s .audio.outputVolume 80
cli -s .audio.speakerPin 53

(sleep 3; reboot -f) &

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Botslab C213 (T23N). GPIO number = bank*32 + pin (PA=0, PB=32).
# Source: stock firmware C213C_v1.0.4.5649 (kernel board data, gpio.config,
# init scripts, audio/sensor module defaults, the stock camera app).
alarm_in=-1
alarm_out=-1
# Reset button PA18, active low (stock gpio-keys KEY_F14)
button=18
# Touch "call" button PB26, active low (stock gpio-keys KEY_F15, wakeup)
button_call=58
# IR-cut filter is on TMI8152 channel 5 (SPI), not on GPIO
ircut1=-1
ircut2=-1
# Status LEDs, active low: PB18 green, PB25 blue
led1=57
led2=50
# IR illuminator PB17 (stock gpio.config "ircut_led")
light_ir=49
light_wl=-1
light_sensor=-1
# SD card detect PB19, active low (stock msc0 platform data)
mmc_cd=51
mmc_pwr=-1
# Speaker amplifier enable PB21, active high (stock app qhHALAOSetPAOnOrOff)
speaker=53
# Ethernet PHY reset PB20, active low (stock U-Boot "ethphy reset"); pulsed by muxes.sh
eth_phy_reset=52
# TMI8152 power stage enable PB31, must stay high (stock audio.ko default spk_gpio)
tmi_en=63
# PA8: stock qihoo_init.sh sets it, but the pad does not respond on T23N
aux_en=-1
usb=-1
Loading