From 0b9c814a3018deab710538109b3cfde1641345f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miku=C5=82a?= Date: Mon, 9 Sep 2024 13:18:41 +0200 Subject: [PATCH 01/51] Update pi.jl (#16) As mentioned in https://github.com/JuliaBerry/PiGPIO.jl/issues/14 --- src/pi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pi.jl b/src/pi.jl index 7768aec..782c92a 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -672,7 +672,7 @@ set_servo_pulsewidth(pi, 17, 2000) # safe clockwise """ function set_servo_pulsewidth(self::Pi, user_gpio, pulsewidth) return _u2i(_pigpio_command( - self.sl, _PI_CMD_SERVO, user_gpio, int(pulsewidth))) + self.sl, _PI_CMD_SERVO, user_gpio, Int(pulsewidth))) end """ From 9f9b0431ba6c92684b4a25a408a3d68ba48875db Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Mon, 9 Sep 2024 09:50:49 -0400 Subject: [PATCH 02/51] Delete appveyor.yml --- appveyor.yml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index e1b4871..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,34 +0,0 @@ -environment: - matrix: - - JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" - -branches: - only: - - master - - /release-.*/ - -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false - -install: -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $("http://s3.amazonaws.com/"+$env:JULIAVERSION), - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia - -build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"PiGPIO\"); Pkg.build(\"PiGPIO\")" - -test_script: - - C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"PiGPIO\")" From 1d152a813791523640b6e36ecad600200952da14 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Mon, 9 Sep 2024 09:50:57 -0400 Subject: [PATCH 03/51] Delete .travis.yml --- .travis.yml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9622a2d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx -julia: - - release - - nightly -notifications: - email: false -# uncomment the following lines to override the default test script -#script: -# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi -# - julia -e 'Pkg.clone(pwd()); Pkg.build("PiGPIO"); Pkg.test("PiGPIO"; coverage=true)' From 2afe25beac35c854f0d9f29bd30a894d205a7b21 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Mon, 9 Sep 2024 09:51:55 -0400 Subject: [PATCH 04/51] Delete REQUIRE --- REQUIRE | 1 - 1 file changed, 1 deletion(-) delete mode 100644 REQUIRE diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index 859ad46..0000000 --- a/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -julia 0.7 From eda13210a19bc46ab90b70ffb23bb3c0582d1b47 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 16:02:14 +0200 Subject: [PATCH 05/51] update docstring for set_mode --- src/pi.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index 782c92a..428b2c1 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -341,16 +341,18 @@ function rxbuf(self::Pi, count) end """ -Sets the GPIO mode. - -gpio:= 0-53. -mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5. - -... -set_mode(pi, 4, pigpio.INPUT) # GPIO 4 as input -set_mode(pi, 17, pigpio.OUTPUT) # GPIO 17 as output -set_mode(pi, 24, pigpio.ALT2) # GPIO 24 as ALT2 -... + set_mode(pi::Pi, pin::Int, mode) + +Sets the GPIO `mode` of the given `pin` (integer between 0 and 53) of the +Pi instance `pi`. The mode con be `PiGPIO.INPUT`, `PiGPIO.OUTPUT`, +`PiGPIO.ALT0`, `PiGPIO.ALT1`, `PiGPIO.ALT2`, `PiGPIO.ALT3`, `PiGPIO.ALT4` or +`PiGPIO.ALT5`. + +```julia +set_mode(pi, 4, PiGPIO.INPUT) # GPIO 4 as input +set_mode(pi, 17, PiGPIO.OUTPUT) # GPIO 17 as output +set_mode(pi, 24, PiGPIO.ALT2) # GPIO 24 as ALT2 +``` """ function set_mode(self::Pi, gpio, mode) return _u2i(_pigpio_command(self.sl, _PI_CMD_MODES, gpio, mode)) From fb68c4963f3fa792c46903ee6b31fbc8785abdd1 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 16:10:32 +0200 Subject: [PATCH 06/51] fix indexing issue and update docstring for error_text --- src/pi.jl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index 428b2c1..17c5066 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -25,19 +25,20 @@ mutable struct Pulse end """ -Returns a text description of a pigpio error. + PiGPIO.error_text(errnum) -errnum:= <0, the error number +Returns a text description of a PiGPIO error number. +`errnum` (`errnum` <0). -... -print(pigpio.error_text(-5)) -level not 0-1 -... +```julia +print(PiGPIO.error_text(-5)) +# output: level not 0-1 +``` """ function error_text(errnum) for e in _errors - if e[0] == errnum - return e[1] + if e[1] == errnum + return e[2] end end return "unknown error ($ernum)" From f84f1c763fff7237040bf2b5c03fdb89f7146194 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 17:18:10 +0200 Subject: [PATCH 07/51] update documentation --- src/pi.jl | 479 +++++++++++++++++++++++++++++------------------------- 1 file changed, 259 insertions(+), 220 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index 17c5066..0d89a47 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -45,15 +45,16 @@ function error_text(errnum) end """ -Returns the microsecond difference between two ticks. + PiGPIO.tickDiff(t1,t2) -t1:= the earlier tick -t2:= the later tick +Returns the microsecond difference between two ticks `t1` (the earlier tick) +and `t2` the later tick. If `t2 - t1 < 0`, it is assumed that the time counter +wrapped around the Int32 limit. -... -print(pigpio.tickDiff(4294967272, 12)) -36 -... +```julia +print(PiGPIO.tickDiff(4294967272, 12)) +# output 36 +``` """ function tickDiff(t1, t2) tDiff = t2 - t1 @@ -173,7 +174,11 @@ function CallbackThread(control, host, port) #self.start() #TODO end -"""Stops notifications.""" +""" + PiGPIO.stop(self::CallbackThread) + +Stops notifications. +""" function stop(self::CallbackThread) if self.go self.go = false @@ -361,13 +366,13 @@ end """ -Returns the GPIO mode. + get_mode(self::Pi, gpio) -gpio:= 0-53. +Returns the GPIO mode for the pin `gpio` (integer between 0 and 53). -Returns a value as follows +Returns a value as follows: -. . +``` 0 = INPUT 1 = OUTPUT 2 = ALT5 @@ -376,12 +381,13 @@ Returns a value as follows 5 = ALT1 6 = ALT2 7 = ALT3 -. . +``` + -... +```julia print(get_mode(pi, 0)) -4 -... +# output 4 +``` """ function get_mode(self::Pi, gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_MODEG, gpio, 0)) @@ -389,16 +395,18 @@ end """ -Sets or clears the internal GPIO pull-up/down resistor. + set_pull_up_down(self::Pi, gpio, pud) -gpio:= 0-53. -pud:= PUD_UP, PUD_DOWN, PUD_OFF. +Sets or clears the internal GPIO pull-up/down resistor +for the pin `gpio` (integer between 0 and 53). +Possible values for `pud` are `PiGPIO.PUD_UP`, `PiGPIO.PUD_DOWN` or +`PiGPIO.PUD_OFF`. -... -set_pull_up_down(pi, 17, pigpio.PUD_OFF) -set_pull_up_down(pi, 23, pigpio.PUD_UP) -set_pull_up_down(pi, 24, pigpio.PUD_DOWN) -... +```julia +set_pull_up_down(pi, 17, PiGPIO.PUD_OFF) +set_pull_up_down(pi, 23, PiGPIO.PUD_UP) +set_pull_up_down(pi, 24, PiGPIO.PUD_DOWN) +``` """ function set_pull_up_down(self::Pi, gpio, pud) return _u2i(_pigpio_command(self.sl, _PI_CMD_PUD, gpio, pud)) @@ -406,46 +414,46 @@ end """ -Returns the GPIO level. + read(self::Pi, gpio) -gpio:= 0-53. +Returns the GPIO level for the pin `gpio` (an integer between 0 and 53). -... -set_mode(pi, 23, pigpio.INPUT) +```julia +set_mode(pi, 23, PiGPIO.INPUT) -set_pull_up_down(pi, 23, pigpio.PUD_DOWN) +set_pull_up_down(pi, 23, PiGPIO.PUD_DOWN) print(read(pi, 23)) -0 +# output 0 -set_pull_up_down(pi, 23, pigpio.PUD_UP) +set_pull_up_down(pi, 23, PiGPIO.PUD_UP) print(read(pi, 23)) -1 -... +# output 1 +``` """ function read(self::Pi, gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_READ, gpio, 0)) end """ -Sets the GPIO level. + write(self::Pi, gpio, level) -GPIO:= 0-53. -level:= 0, 1. +Sets the GPIO level for the pin `gpio` (an integer between 0 and 53) where +level is 0 or 1. If PWM or servo pulses are active on the GPIO they are switched off. -... -set_mode(pi, 17, pigpio.OUTPUT) +```julia +set_mode(pi, 17, PiGPIO.OUTPUT) write(pi, 17,0) print(read(pi, 17)) -0 +# output 0 write(pi, 17,1) print(read(pi, 17)) -1 -... +# output 1 +``` """ function write(self::Pi, gpio, level) return _u2i(_pigpio_command(self.sl, _PI_CMD_WRITE, gpio, level)) @@ -453,20 +461,22 @@ end """ + PiGPIO.set_PWM_dutycycle(self::Pi, user_gpio, dutycycle) + Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. user_gpio:= 0-31. dutycycle:= 0-range (range defaults to 255). -The [*set_PWM_range*] function can change the default range of 255. +The `set_PWM_range` function can change the default range of 255. -... +```julia set_PWM_dutycycle(pi, 4, 0) # PWM off set_PWM_dutycycle(pi, 4, 64) # PWM 1/4 on set_PWM_dutycycle(pi, 4, 128) # PWM 1/2 on set_PWM_dutycycle(pi, 4, 192) # PWM 3/4 on set_PWM_dutycycle(pi, 4, 255) # PWM full on -... +``` """ function set_PWM_dutycycle(self::Pi, user_gpio, dutycycle) return _u2i(_pigpio_command( @@ -474,15 +484,13 @@ function set_PWM_dutycycle(self::Pi, user_gpio, dutycycle) end """ -Returns the PWM dutycycle being used on the GPIO. + PiGPIO.get_PWM_dutycycle(self::Pi, user_gpio) +Returns the PWM dutycycle being used on the GPIO. user_gpio:= 0-31. -Returns the PWM dutycycle. - - For normal PWM the dutycycle will be out of the defined range -for the GPIO (see [*get_PWM_range*]). +for the GPIO (see `get_PWM_range`). If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). @@ -490,55 +498,58 @@ dutycycle will be 500000 (500k) out of 1000000 (1M). If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). -... +```julia set_PWM_dutycycle(pi, 4, 25) print(get_PWM_dutycycle(pi, 4)) -25 +# output 25 set_PWM_dutycycle(pi, 4, 203) print(get_PWM_dutycycle(pi, 4)) -203 -... +# output 203 +``` """ function get_PWM_dutycycle(self::Pi, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_GDC, user_gpio, 0)) end """ -Sets the range of PWM values to be used on the GPIO. + PiGPIO.set_PWM_range(self::Pi, user_gpio, range_) -user_gpio:= 0-31. - range_:= 25-40000. +Sets the range of PWM values to be used on the GPIO. +`user_gpio` is an integer between 0 and 31 and `range_` is between 25 and 40000. -... +```julia set_PWM_range(pi, 9, 100) # now 25 1/4, 50 1/2, 75 3/4 on set_PWM_range(pi, 9, 500) # now 125 1/4, 250 1/2, 375 3/4 on set_PWM_range(pi, 9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on -... +``` """ function set_PWM_range(self::Pi, user_gpio, range_) return _u2i(_pigpio_command(self.sl, _PI_CMD_PRS, user_gpio, range_)) end """ -Returns the range of PWM values being used on the GPIO. + PiGPIO.get_PWM_range(self::Pi, user_gpio) -user_gpio:= 0-31. +Returns the range of PWM values being used on the GPIO. +`user_gpio` is an integer between 0 and 31. If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). -... +```julia set_PWM_range(pi, 9, 500) print(get_PWM_range(pi, 9)) -500 -... +# output 500 +``` """ function get_PWM_range(self::Pi, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_PRG, user_gpio, 0)) end """ + PiGPIO.get_PWM_real_range(self::Pi, user_gpio) + Returns the real (underlying) range of PWM values being used on the GPIO. @@ -550,11 +561,11 @@ real range will be 1000000 (1M). If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. -... +```julia set_PWM_frequency(pi, 4, 800) print(get_PWM_real_range(pi, 4)) -250 -... +# output 250 +``` """ function get_PWM_real_range(self::Pi, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_PRRG, user_gpio, 0)) @@ -581,7 +592,7 @@ sample rate is set when the pigpio daemon is started. The frequencies for each sample rate are -. . +``` Hertz 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 @@ -602,9 +613,10 @@ rate 10: 4000 2000 1000 800 500 400 250 200 160 125 100 80 50 40 25 20 10 5 -. . +``` + -... +```julia set_PWM_frequency(pi, 4,0) print(get_PWM_frequency(pi, 4)) 10 @@ -612,7 +624,7 @@ print(get_PWM_frequency(pi, 4)) set_PWM_frequency(pi, 4,100000) print(get_PWM_frequency(pi, 4)) 8000 -... +``` """ function set_PWM_frequency(self::Pi, user_gpio, frequency) return _u2i( @@ -627,15 +639,15 @@ user_gpio:= 0-31. Returns the frequency (in Hz) used for the GPIO. For normal PWM the frequency will be that defined for the GPIO -by [*set_PWM_frequency*]. +by `set_PWM_frequency`. If a hardware clock is active on the GPIO the reported frequency -will be that set by [*hardware_clock*]. +will be that set by `hardware_clock`. If hardware PWM is active on the GPIO the reported frequency -will be that set by [*hardware_PWM*]. +will be that set by `hardware_PWM`. -... +```julia set_PWM_frequency(pi, 4,0) print(get_PWM_frequency(pi, 4)) 10 @@ -643,7 +655,7 @@ print(get_PWM_frequency(pi, 4)) set_PWM_frequency(pi, 4, 800) print(get_PWM_frequency(pi, 4)) 800 -... +``` """ function get_PWM_frequency(self::Pi, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_PFG, user_gpio, 0)) @@ -666,12 +678,12 @@ safe and represents the mid-point of rotation. You can DAMAGE a servo if you command it to move beyond its limits. -... +```julia set_servo_pulsewidth(pi, 17, 0) # off set_servo_pulsewidth(pi, 17, 1000) # safe anti-clockwise set_servo_pulsewidth(pi, 17, 1500) # centre set_servo_pulsewidth(pi, 17, 2000) # safe clockwise -... +``` """ function set_servo_pulsewidth(self::Pi, user_gpio, pulsewidth) return _u2i(_pigpio_command( @@ -685,7 +697,7 @@ user_gpio:= 0-31. Returns the servo pulsewidth. -... +```julia set_servo_pulsewidth(pi, 4, 525) print(get_servo_pulsewidth(pi, 4)) 525 @@ -693,13 +705,15 @@ print(get_servo_pulsewidth(pi, 4)) set_servo_pulsewidth(pi, 4, 2130) print(get_servo_pulsewidth(pi, 4)) 2130 -... +``` """ function get_servo_pulsewidth(self::Pi, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_GPW, user_gpio, 0)) end """ + PiGPIO.notify_open(self::Pi) + Returns a notification handle (>=0). A notification is a method for being notified of GPIO state @@ -708,30 +722,30 @@ changes via a pipe. Pipes are only accessible from the local machine so this function serves no purpose if you are using Python from a remote machine. The in-built (socket) notifications -provided by [*callback*] should be used instead. +provided by `callback` should be used instead. -Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). +Notifications for handle `x` will be available at the pipe +named `/dev/pigpiox` (where `x` is the handle number). E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. +read from `/dev/pigpio15`. Notifications have the following structure. -. . +``` I seqno I flags I tick I level -. . +``` seqno: starts at 0 each time the handle is opened and then increments by one for each report. -flags: two flags are defined, PI_NTFY_FLAGS_WDOG and -PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) +flags: two flags are defined, `PI_NTFY_FLAGS_WDOG` and +`PI_NTFY_FLAGS_ALIVE`. If bit 5 is set (`PI_NTFY_FLAGS_WDOG`) then bits 0-4 of the flags indicate a GPIO which has had a -watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this +watchdog timeout; if bit 6 is set (`PI_NTFY_FLAGS_ALIVE`) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. @@ -741,11 +755,11 @@ around after 1h12m. level: indicates the level of each GPIO. If bit 1<= 0 notify_begin(pi, h, 1234) -... +``` """ function notify_open(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_NO, 0, 0)) @@ -754,7 +768,7 @@ end """ Starts notifications on a handle. -handle:= >=0 (as returned by a prior call to [*notify_open*]) +handle:= >=0 (as returned by a prior call to `notify_open`) bits:= a 32 bit mask indicating the GPIO to be notified. The notification sends state changes for each GPIO whose @@ -763,11 +777,11 @@ corresponding bit in bits is set. The following code starts notifications for GPIO 1, 4, 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). -... -h = notify_open(pi, ) +```julia +h = notify_open(pi) if h >= 0 notify_begin(pi, h, 1234) -... +``` """ function notify_begin(self::Pi, handle, bits) return _u2i(_pigpio_command(self.sl, _PI_CMD_NB, handle, bits)) @@ -776,21 +790,21 @@ end """ Pauses notifications on a handle. -handle:= >=0 (as returned by a prior call to [*notify_open*]) +handle:= >=0 (as returned by a prior call to `notify_open`) Notifications for the handle are suspended until -[*notify_begin*] is called again. +`notify_begin` is called again. -... -h = notify_open(pi, ) +```julia +h = notify_open(pi) if h >= 0 notify_begin(pi, h, 1234) - ... + # ... notify_pause(pi, h) - ... + # ... notify_begin(pi, h, 1234) - ... -... + # ... +``` """ function notify_pause(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_NB, handle, 0)) @@ -799,16 +813,16 @@ end """ Stops notifications on a handle and releases the handle for reuse. -handle:= >=0 (as returned by a prior call to [*notify_open*]) +handle:= >=0 (as returned by a prior call to `notify_open`) -... -h = notify_open(pi, ) +```julia +h = notify_open(pi) if h >= 0 notify_begin(pi, h, 1234) - ... + # ... notify_close(pi, h) - ... -... + # ... +``` """ function notify_close(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_NC, handle, 0)) @@ -833,10 +847,10 @@ to the fifo with the flags set to indicate a watchdog timeout. The callback class interprets the flags and will call registered callbacks for the GPIO with level TIMEOUT. -... +```julia set_watchdog(pi, 23, 1000) # 1000 ms watchdog on GPIO 23 set_watchdog(pi, 23, 0) # cancel watchdog on GPIO 23 -... +``` """ function set_watchdog(self::Pi, user_gpio, wdog_timeout) return _u2i(_pigpio_command( @@ -849,10 +863,10 @@ Returns the levels of the bank 1 GPIO (GPIO 0-31). The returned 32 bit integer has a bit set if the corresponding GPIO is high. GPIO n has bit value (1<=0, default 0. -arg2:= >=0, default 0. -argx:= extra arguments (each 0-255), default empty. +`arg1` is >=0, default 0. +`arg2` is >=0, default 0. +`argx` is an extra arguments (each 0-255), default empty. The returned value is an integer which by convention should be >=0 for OK and <0 for error. -... -value = custom_1(pi, ) +```julia +value = PiGPIO.custom_1(pi) -value = custom_1(pi, 23) +value = PiGPIO.custom_1(pi, 23) -value = custom_1(pi, 0, 55) +value = PiGPIO.custom_1(pi, 0, 55) -value = custom_1(pi, 23, 56, [1, 5, 7]) +value = PiGPIO.custom_1(pi, 23, 56, [1, 5, 7]) -value = custom_1(pi, 23, 56, b"hello") +value = PiGPIO.custom_1(pi, 23, 56, b"hello") -value = custom_1(pi, 23, 56, "hello") -... +value = PiGPIO.custom_1(pi, 23, 56, "hello") +``` """ function custom_1(self, arg1=0, arg2=0, argx=[]) # I p1 arg1 @@ -1146,28 +1175,29 @@ function custom_1(self, arg1=0, arg2=0, argx=[]) end """ + PiGPIO.custom_2(self, arg1=0, argx=[], retMax=8192) + Calls a pigpio function customised by the user. -arg1:= >=0, default 0. -argx:= extra arguments (each 0-255), default empty. -retMax:= >=0, maximum number of bytes to return, default 8192. +`arg1` is >=0, default 0. `argx` extra arguments (each 0-255), default empty. +`retMax` is >=0, maximum number of bytes to return, default 8192. The returned value is a tuple of the number of bytes returned and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... -(count, data) = custom_2(pi, ) +```julia +(count, data) = PiGPIO.custom_2(pi) -(count, data) = custom_2(pi, 23) +(count, data) = PiGPIO.custom_2(pi, 23) -(count, data) = custom_2(pi, 23, [1, 5, 7]) +(count, data) = PiGPIO.custom_2(pi, 23, [1, 5, 7]) -(count, data) = custom_2(pi, 23, b"hello") +(count, data) = PiGPIO.custom_2(pi, 23, b"hello") -(count, data) = custom_2(pi, 23, "hello", 128) -... +(count, data) = PiGPIO.custom_2(pi, 23, "hello", 128) +``` """ function custom_2(self, arg1=0, argx=[], retMax=8192) # I p1 arg1 @@ -1189,11 +1219,13 @@ function custom_2(self, arg1=0, argx=[], retMax=8192) end """ + PiGPIO.callback(self::Pi, user_gpio, edge=RISING_EDGE, func=nothing) + Calls a user supplied function (a callback) whenever the specified GPIO edge is detected. user_gpio:= 0-31. -edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. +edge:= `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE` (default), or `PiGPIO.FALLING_EDGE`. func:= user supplied callback function. The user supplied callback receives three parameters, the GPIO, @@ -1209,15 +1241,14 @@ The callback may be cancelled by calling the cancel function. A GPIO may have multiple callbacks (although I can't think of a reason to do so). -... -end - +```julia function cbf(gpio, level, tick) -print(gpio, level, tick) + print(gpio, level, tick) +end -cb1 = callback(pi, 22, pigpio.EITHER_EDGE, cbf) +cb1 = callback(pi, 22, PiGPIO.EITHER_EDGE, cbf) -cb2 = callback(pi, 4, pigpio.EITHER_EDGE) +cb2 = callback(pi, 4, PiGPIO.EITHER_EDGE) cb3 = callback(pi, 17) @@ -1226,7 +1257,7 @@ print(cb3.tally()) cb3.reset_tally() cb1.cancel() # To cancel callback cb1. -... +``` """ function callback(self::Pi, user_gpio, edge=RISING_EDGE, func=nothing) return _callback(self._notify, user_gpio, edge, func) @@ -1246,22 +1277,22 @@ the number of seconds specified by timeout has expired. Do not use this function for precise timing purposes, the edge is only checked 20 times a second. Whenever you need to know the accurate time of GPIO events use -a [*callback*] function. +a `callback` function. The function returns true if the edge is detected, otherwise false. -... +```julia if wait_for_edge(pi, 23) print("Rising edge detected") else print("wait for edge timed out") -if wait_for_edge(pi, 23, pigpio.FALLING_EDGE, 5.0) +if wait_for_edge(pi, 23, PiGPIO.FALLING_EDGE, 5.0) print("Falling edge detected") else print("wait for falling edge timed out") -... +``` """ function wait_for_edge(self::Pi, user_gpio, edge=RISING_EDGE, wait_timeout=60.0) a = _wait_for_edge(self.notify, user_gpio, edge, wait_timeout) @@ -1269,13 +1300,16 @@ function wait_for_edge(self::Pi, user_gpio, edge=RISING_EDGE, wait_timeout=60.0) end """ + Pi(; host = get(ENV, "PIGPIO_ADDR", ""), + port = get(ENV, "PIGPIO_PORT", 8888)) + Grants access to a Pi's GPIO. -host:= the host name of the Pi on which the pigpio daemon is +`host` is the host name of the Pi on which the pigpio daemon is running. The default is localhost unless overridden by the PIGPIO_ADDR environment variable. -port:= the port number on which the pigpio daemon is listening. +`port` is the port number on which the pigpio daemon is listening. The default is 8888 unless overridden by the PIGPIO_PORT environment variable. The pigpio daemon must have been started with the same port number. @@ -1283,19 +1317,20 @@ port:= the port number on which the pigpio daemon is listening. This connects to the pigpio daemon and reserves resources to be used for sending commands and receiving notifications. -An instance attribute [*connected*] may be used to check the +An instance attribute `connected` may be used to check the success of the connection. If the connection is established -successfully [*connected*] will be true, otherwise false. +successfully `connected` will be true, otherwise false. -... -pi = pigpio.pi() # use defaults -pi = pigpio.pi('mypi') # specify host, default port -pi = pigpio.pi('mypi', 7777) # specify host and port +```julia +pi = PiGPIO.Pi() # use defaults +pi = PiGPIO.Pi(host = "mypi") # specify host, default port +pi = PiGPIO.Pi(host = "mypi", port = 7777) # specify host and port -pi = pigpio.pi() # exit script if no connection -if not pi.connected -exit() -... +pi = PiGPIO.Pi() # exit script if no connection +if !pi.connected + exit() +end +``` """ function Pi(; host = get(ENV, "PIGPIO_ADDR", ""), port = get(ENV, "PIGPIO_PORT", 8888)) port = Int(port) @@ -1327,10 +1362,14 @@ function Pi(; host = get(ENV, "PIGPIO_ADDR", ""), port = get(ENV, "PIGPIO_PORT", end -"""Release pigpio resources. -... -stop(pi) -... +""" + PiGPIO.stop(self::Pi) + +Release pigpio resources. + +```julia +PiGPIO.stop(pi) +``` """ function stop(self::Pi) self.connected = false From 7bd7ecc2c4bea52aa9507acd123081d6d08c7055 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 17:34:28 +0200 Subject: [PATCH 08/51] add missing comma --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 6e8a85f..eacc9ed 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,7 +12,7 @@ makedocs( modules = [PiGPIO], pages = [ "index.md", - "Tutorial" => "tutorial.md" + "Tutorial" => "tutorial.md", "API Docs" => "api.md", "Examples" => [ "Blink Once" => "examples/01_blink.md", From c97542f32ddb8c10de6d4a1318b8c53205fbf18b Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 17:35:39 +0200 Subject: [PATCH 09/51] markdown files are expected to be in docs/src --- docs/{ => src}/tutorial.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{ => src}/tutorial.md (100%) diff --git a/docs/tutorial.md b/docs/src/tutorial.md similarity index 100% rename from docs/tutorial.md rename to docs/src/tutorial.md From b9bf1806b7427c552300e4bf37381e53ba8cdbbe Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 18:14:46 +0200 Subject: [PATCH 10/51] dos2unix --- Project.toml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 2ea1255..65a6ff2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,9 +1,9 @@ -name = "PiGPIO" -uuid = "bb151fc1-c6dc-5496-8ed6-07f94907e623" -version = "0.2.0" - -[compat] -julia = "1" - -[deps] -Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" +name = "PiGPIO" +uuid = "bb151fc1-c6dc-5496-8ed6-07f94907e623" +version = "0.2.0" + +[compat] +julia = "1" + +[deps] +Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" From e1b86f482f92897beea47f24ecc9c4d6356d545a Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 18:22:20 +0200 Subject: [PATCH 11/51] explicit version for Sockets --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 65a6ff2..f79e1f7 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ version = "0.2.0" [compat] julia = "1" +Sockets = "1" [deps] Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" From 931bf1c8a5a93afbe50b2bdf72ca391ce6b8b275 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 18:53:20 +0200 Subject: [PATCH 12/51] document option to make the documentation without a Raspberry Pi --- docs/make.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/make.jl b/docs/make.jl index eacc9ed..44cc43b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -10,6 +10,9 @@ makedocs( sitename = "PiGPIO", format = Documenter.HTML(), modules = [PiGPIO], + # examples need to be run on a Raspberry Pi + # doctest = false, + # draft = true, pages = [ "index.md", "Tutorial" => "tutorial.md", From a7feab5a19ab5f799d027f7956fec454ce359a8e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:01:31 +0200 Subject: [PATCH 13/51] fix doc --- src/pi.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index 0d89a47..782d657 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -14,9 +14,9 @@ end """ A class to store pulse information. -gpio_on: the GPIO to switch on at the start of the pulse. -gpio_off: the GPIO to switch off at the start of the pulse. -delay: the delay in microseconds before the next pulse. +`gpio_on`: the GPIO to switch on at the start of the pulse. +`gpio_off`: the GPIO to switch off at the start of the pulse. +`delay`: the delay in microseconds before the next pulse. """ mutable struct Pulse gpio_on::Int @@ -140,7 +140,7 @@ end """An ADT class to hold callback information gpio:= Broadcom GPIO number. - edge:= EITHER_EDGE, RISING_EDGE, or FALLING_EDGE. + edge:= `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE`, or `PiGPIO.FALLING_EDGE`. func:= a user function taking three arguments (GPIO, level, tick). """ mutable struct Callback_ADT From c42e7d52d95e5cd6683e5eacde94388faea5cc03 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:02:52 +0200 Subject: [PATCH 14/51] use markdown code fences --- src/i2c.jl | 156 ++++++++++++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 5af0bf7..d0d8064 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -18,7 +18,7 @@ For the SMBus commands the low level transactions are shown at the end of the function description. The following abbreviations are used. -. . +``` S (1 bit) : Start bit P (1 bit) : Stop bit Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. @@ -29,11 +29,11 @@ Data (8 bits): A data byte. Count (8 bits): A byte defining the length of a block operation. [..]: Data sent by the device. -. . +``` -... +```julia h = i2c_open(pi, 1, 0x53) # open device at address 0x53 on bus 1 -... +``` """ function i2c_open(self::Pi, i2c_bus, i2c_address, i2c_flags=0) # I p1 i2c_bus @@ -51,9 +51,9 @@ Closes the I2C device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). -... +```julia i2c_close(pi, h) -... +``` """ function i2c_close(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CC, handle, 0)) @@ -66,14 +66,14 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). bit:= 0 or 1, the value to write. SMBus 2.0 5.5.1 - Quick command. -. . +``` S Addr bit [A] P -. . +``` -... +```julia i2c_write_quick(pi, 0, 1) # send 1 to device 0 i2c_write_quick(pi, 3, 0) # send 0 to device 3 -... +``` """ function i2c_write_quick(self::Pi, handle, bit) return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CWQ, handle, bit)) @@ -86,14 +86,14 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). byte_val:= 0-255, the value to write. SMBus 2.0 5.5.2 - Send byte. -. . +``` S Addr Wr [A] byte_val [A] P -. . +``` -... +```julia i2c_write_byte(pi, 1, 17) # send byte 17 to device 1 i2c_write_byte(pi, 2, 0x23) # send byte 0x23 to device 2 -... +``` """ function i2c_write_byte(self::Pi, handle, byte_val) return _u2i( @@ -106,13 +106,13 @@ Reads a single byte from the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). SMBus 2.0 5.5.3 - Receive byte. -. . +``` S Addr Rd [A] [Data] NA P -. . +``` -... +```julia b = i2c_read_byte(pi, 2) # read a byte from device 2 -... +``` """ function i2c_read_byte(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRS, handle, 0)) @@ -127,17 +127,17 @@ reg:= >=0, the device register. byte_val:= 0-255, the value to write. SMBus 2.0 5.5.4 - Write byte. -. . +``` S Addr Wr [A] reg [A] byte_val [A] P -. . +``` -... +```julia # send byte 0xC5 to reg 2 of device 1 i2c_write_byte_data(pi, 1, 2, 0xC5) # send byte 9 to reg 4 of device 2 i2c_write_byte_data(pi, 2, 4, 9) -... +``` """ function i2c_write_byte_data(self::Pi, handle, reg, byte_val) # I p1 handle @@ -160,17 +160,17 @@ reg:= >=0, the device register. word_val:= 0-65535, the value to write. SMBus 2.0 5.5.4 - Write word. -. . +``` S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P -. . +``` -... +```julia # send word 0xA0C5 to reg 5 of device 4 i2c_write_word_data(pi, 4, 5, 0xA0C5) # send word 2 to reg 2 of device 5 i2c_write_word_data(pi, 5, 2, 23) -... +``` """ function i2c_write_word_data(self::Pi, handle, reg, word_val) # I p1 handle @@ -192,17 +192,17 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read byte. -. . +``` S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P -. . +``` -... +```julia # read byte from reg 17 of device 2 b = i2c_read_byte_data(pi, 2, 17) # read byte from reg 1 of device 0 b = i2c_read_byte_data(pi, 0, 1) -... +``` """ function i2c_read_byte_data(self, handle, reg) return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRB, handle, reg)) @@ -216,17 +216,17 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read word. -. . +``` S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -. . +``` -... +```julia # read word from reg 2 of device 3 w = i2c_read_word_data(pi, 3, 2) # read word from reg 7 of device 2 w = i2c_read_word_data(pi, 2, 7) -... +``` """ function i2c_read_word_data(self, handle, reg) return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRW, handle, reg)) @@ -241,15 +241,15 @@ reg:= >=0, the device register. word_val:= 0-65535, the value to write. SMBus 2.0 5.5.6 - Process call. -. . +``` S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -. . +``` -... +```julia r = i2c_process_call(pi, h, 4, 0x1231) r = i2c_process_call(pi, h, 6, 0) -... +``` """ function i2c_process_call(self, handle, reg, word_val) # I p1 handle @@ -272,12 +272,12 @@ reg:= >=0, the device register. data:= the bytes to write. SMBus 2.0 5.5.7 - Block write. -. . +``` S Addr Wr [A] reg [A] length(data) [A] data0 [A] data1 [A] ... [A] datan [A] P -. . +``` -... +```julia i2c_write_block_data(pi, 4, 5, b'hello') i2c_write_block_data(pi, 4, 5, "data bytes") @@ -285,7 +285,7 @@ i2c_write_block_data(pi, 4, 5, "data bytes") i2c_write_block_data(pi, 5, 0, b'\\x00\\x01\\x22') i2c_write_block_data(pi, 6, 2, [0, 1, 0x22]) -... +``` """ function i2c_write_block_data(self, handle, reg, data) # I p1 handle @@ -309,10 +309,10 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.7 - Block read. -. . +``` S Addr Wr [A] reg [A] S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P -. . +``` The amount of returned data is set by the device. @@ -321,13 +321,13 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (b, d) = i2c_read_block_data(pi, h, 10) if b >= 0 # process data else # process read failure -... +``` """ function i2c_read_block_data(self::Pi, handle, reg) # Don't raise exception. Must release lock. @@ -356,17 +356,17 @@ be sent and a minimum of 1 byte may be received. The total number of bytes sent/received must be 32 or less. SMBus 2.0 5.5.8 - Block write-block read. -. . +``` S Addr Wr [A] reg [A] length(data) [A] data0 [A] ... datan [A] S Addr Rd [A] [Count] A [Data] ... A P -. . +``` The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (b, d) = i2c_block_process_call(pi, h, 10, b'\\x02\\x05\\x00') (b, d) = i2c_block_process_call(pi, h, 10, b'abcdr') @@ -374,7 +374,7 @@ the error code). (b, d) = i2c_block_process_call(pi, h, 10, "abracad") (b, d) = i2c_block_process_call(pi, h, 10, [2, 5, 16]) -... +``` """ function i2c_block_process_call(self::Pi, handle, reg, data) # I p1 handle @@ -403,11 +403,11 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. data:= the bytes to write. -. . +``` S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P -. . +``` -... +```julia i2c_write_i2c_block_data(pi, 4, 5, 'hello') i2c_write_i2c_block_data(pi, 4, 5, b'hello') @@ -415,7 +415,7 @@ i2c_write_i2c_block_data(pi, 4, 5, b'hello') i2c_write_i2c_block_data(pi, 5, 0, b'\\x00\\x01\\x22') i2c_write_i2c_block_data(pi, 6, 2, [0, 1, 0x22]) -... +``` """ function i2c_write_i2c_block_data(self::Pi, handle, reg, data) # I p1 handle @@ -439,23 +439,23 @@ handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. count:= >0, the number of bytes to read. -. . +``` S Addr Wr [A] reg [A] S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -. . +``` The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (b, d) = i2c_read_i2c_block_data(pi, h, 4, 32) if b >= 0 # process data else # process read failure -... +``` """ function i2c_read_i2c_block_data(self::Pi, handle, reg, count) # I p1 handle @@ -485,18 +485,18 @@ with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). count:= >0, the number of bytes to read. -. . +``` S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -. . +``` The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (count, data) = i2c_read_device(pi, h, 12) -... +``` """ function i2c_read_device(self::Pi, handle, count) # Don't raise exception. Must release lock. @@ -517,11 +517,11 @@ Writes the data bytes to the raw device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). data:= the bytes to write. -. . +``` S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P -. . +``` -... +```julia i2c_write_device(pi, h, b"\\x12\\x34\\xA8") i2c_write_device(pi, h, b"help") @@ -529,7 +529,7 @@ i2c_write_device(pi, h, b"help") i2c_write_device(pi, h, 'help') i2c_write_device(pi, h, [23, 56, 231]) -... +``` """ function i2c_write_device(self::Pi, handle, data) # I p1 handle @@ -558,9 +558,9 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (count, data) = i2c_zip(pi, h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) -... +``` The following command codes are supported @@ -585,7 +585,7 @@ previous value until updated. Any read I2C data is concatenated in the returned bytearray. -... +``` Set address 0x53, write 0x32, read 6 bytes Set address 0x1E, write 0x03, read 6 bytes Set address 0x68, write 0x1B, read 8 bytes @@ -595,7 +595,7 @@ End 0x04 0x1E 0x07 0x01 0x03 0x06 0x06 0x04 0x68 0x07 0x01 0x1B 0x06 0x08 0x00 -... +``` """ function i2c_zip(self::Pi, handle, data) # I p1 handle @@ -640,9 +640,9 @@ NOTE The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -... +```julia h = bb_i2c_open(pi, 4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps -... +``` """ function bb_i2c_open(self::Pi, SDA, SCL, baud=100000) # I p1 SDA @@ -664,9 +664,9 @@ SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -... +```julia bb_i2c_close(pi, SDA) -... +``` """ function bb_i2c_close(self::Pi, SDA) return _u2i(_pigpio_command(self.sl, _PI_CMD_BI2CC, SDA, 0)) @@ -686,10 +686,10 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (count, data) = pi.bb_i2c_zip( h, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) -... +``` The following command codes are supported @@ -715,7 +715,7 @@ No flags are currently defined. Any read I2C data is concatenated in the returned bytearray. -... +``` Set address 0x53 start, write 0x32, (re)start, read 6 bytes, stop Set address 0x1E @@ -734,7 +734,7 @@ End 0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 0x00 -... +``` """ function bb_i2c_zip(self::Pi, SDA, data) # I p1 SDA From c37ffba50189688de439d0114ad993f370c4b5d4 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:03:18 +0200 Subject: [PATCH 15/51] dos2unix --- src/i2c.jl | 1512 ++++++++++++++++++++++++++-------------------------- 1 file changed, 756 insertions(+), 756 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index d0d8064..2953fb4 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -1,756 +1,756 @@ -""" -Returns a handle (>=0) for the device at the I2C bus address. - -i2c_bus:= >=0. -i2c_address:= 0-0x7F. -i2c_flags:= 0, no flags are currently defined. - -Normally you would only use the [*i2c_**] functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard SMBus -module instead. - -Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. - -For the SMBus commands the low level transactions are shown -at the end of the function description. The following -abbreviations are used. - -``` -S (1 bit) : Start bit -P (1 bit) : Stop bit -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -A, NA (1 bit) : Accept and not accept bit. -Addr (7 bits): I2C 7 bit address. -reg (8 bits): Command byte, which often selects a register. -Data (8 bits): A data byte. -Count (8 bits): A byte defining the length of a block operation. - -[..]: Data sent by the device. -``` - -```julia -h = i2c_open(pi, 1, 0x53) # open device at address 0x53 on bus 1 -``` -""" -function i2c_open(self::Pi, i2c_bus, i2c_address, i2c_flags=0) - # I p1 i2c_bus - # I p2 i2c_addr - # I p3 4 - ## extension ## - # I i2c_flags - extents = [pack("I", i2c_flags)] - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents)) -end - -""" -Closes the I2C device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). - -```julia -i2c_close(pi, h) -``` -""" -function i2c_close(self::Pi, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CC, handle, 0)) -end - -""" -Sends a single bit to the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -bit:= 0 or 1, the value to write. - -SMBus 2.0 5.5.1 - Quick command. -``` -S Addr bit [A] P -``` - -```julia -i2c_write_quick(pi, 0, 1) # send 1 to device 0 -i2c_write_quick(pi, 3, 0) # send 0 to device 3 -``` -""" -function i2c_write_quick(self::Pi, handle, bit) - return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CWQ, handle, bit)) -end - -""" -Sends a single byte to the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -byte_val:= 0-255, the value to write. - -SMBus 2.0 5.5.2 - Send byte. -``` -S Addr Wr [A] byte_val [A] P -``` - -```julia -i2c_write_byte(pi, 1, 17) # send byte 17 to device 1 -i2c_write_byte(pi, 2, 0x23) # send byte 0x23 to device 2 -``` -""" -function i2c_write_byte(self::Pi, handle, byte_val) - return _u2i( - _pigpio_command(self.sl, _PI_CMD_I2CWS, handle, byte_val)) -end - -""" -Reads a single byte from the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). - -SMBus 2.0 5.5.3 - Receive byte. -``` -S Addr Rd [A] [Data] NA P -``` - -```julia -b = i2c_read_byte(pi, 2) # read a byte from device 2 -``` -""" -function i2c_read_byte(self::Pi, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRS, handle, 0)) -end - -""" -Writes a single byte to the specified register of the device -associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -byte_val:= 0-255, the value to write. - -SMBus 2.0 5.5.4 - Write byte. -``` -S Addr Wr [A] reg [A] byte_val [A] P -``` - -```julia -# send byte 0xC5 to reg 2 of device 1 -i2c_write_byte_data(pi, 1, 2, 0xC5) - -# send byte 9 to reg 4 of device 2 -i2c_write_byte_data(pi, 2, 4, 9) -``` -""" -function i2c_write_byte_data(self::Pi, handle, reg, byte_val) - # I p1 handle - # I p2 reg - # I p3 4 - ## extension ## - # I byte_val - extents = IOBuffer - write(extents, byte_val) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CWB, handle, reg, 4, extents)) -end - -""" -Writes a single 16 bit word to the specified register of the -device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -word_val:= 0-65535, the value to write. - -SMBus 2.0 5.5.4 - Write word. -``` -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P -``` - -```julia -# send word 0xA0C5 to reg 5 of device 4 -i2c_write_word_data(pi, 4, 5, 0xA0C5) - -# send word 2 to reg 2 of device 5 -i2c_write_word_data(pi, 5, 2, 23) -``` -""" -function i2c_write_word_data(self::Pi, handle, reg, word_val) - # I p1 handle - # I p2 reg - # I p3 4 - ## extension ## - # I word_val - extents = IOBuffer - write(extents, word_val) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CWW, handle, reg, 4, extents)) -end - -""" -Reads a single byte from the specified register of the device -associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. - -SMBus 2.0 5.5.5 - Read byte. -``` -S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P -``` - -```julia -# read byte from reg 17 of device 2 -b = i2c_read_byte_data(pi, 2, 17) - -# read byte from reg 1 of device 0 -b = i2c_read_byte_data(pi, 0, 1) -``` -""" -function i2c_read_byte_data(self, handle, reg) - return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRB, handle, reg)) -end - -""" -Reads a single 16 bit word from the specified register of the -device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. - -SMBus 2.0 5.5.5 - Read word. -``` -S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -``` - -```julia -# read word from reg 2 of device 3 -w = i2c_read_word_data(pi, 3, 2) - -# read word from reg 7 of device 2 -w = i2c_read_word_data(pi, 2, 7) -``` -""" -function i2c_read_word_data(self, handle, reg) - return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRW, handle, reg)) -end - -""" -Writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -word_val:= 0-65535, the value to write. - -SMBus 2.0 5.5.6 - Process call. -``` -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] -S Addr Rd [A] [DataLow] A [DataHigh] NA P -``` - -```julia -r = i2c_process_call(pi, h, 4, 0x1231) -r = i2c_process_call(pi, h, 6, 0) -``` -""" -function i2c_process_call(self, handle, reg, word_val) - # I p1 handle - # I p2 reg - # I p3 4 - ## extension ## - # I word_val - extents = IOBuffer - write(extents, word_val) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CPC, handle, reg, 4, extents)) -end - -""" -Writes up to 32 bytes to the specified register of the device -associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -data:= the bytes to write. - -SMBus 2.0 5.5.7 - Block write. -``` -S Addr Wr [A] reg [A] length(data) [A] data0 [A] data1 [A] ... [A] -datan [A] P -``` - -```julia -i2c_write_block_data(pi, 4, 5, b'hello') - -i2c_write_block_data(pi, 4, 5, "data bytes") - -i2c_write_block_data(pi, 5, 0, b'\\x00\\x01\\x22') - -i2c_write_block_data(pi, 6, 2, [0, 1, 0x22]) -``` -""" -function i2c_write_block_data(self, handle, reg, data) -# I p1 handle -# I p2 reg -# I p3 len -## extension ## -# s len data bytes - if length(data) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CWK, handle, reg, length(data), data)) - else - return 0 - end -end - -""" -Reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. - -SMBus 2.0 5.5.7 - Block read. -``` -S Addr Wr [A] reg [A] -S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P -``` - -The amount of returned data is set by the device. - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(b, d) = i2c_read_block_data(pi, h, 10) -if b >= 0 -# process data -else -# process read failure -``` -""" -function i2c_read_block_data(self::Pi, handle, reg) - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command(self.sl, _PI_CMD_I2CRK, handle, reg, false)) - if bytes > 0 - data = rxbuf(bytes) - else - data = "" - end - - unlock(self.sl.l) - return bytes, data -end - -""" -Writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -data:= the bytes to write. - -The SMBus 2.0 documentation states that a minimum of 1 byte may -be sent and a minimum of 1 byte may be received. The total -number of bytes sent/received must be 32 or less. - -SMBus 2.0 5.5.8 - Block write-block read. -``` -S Addr Wr [A] reg [A] length(data) [A] data0 [A] ... datan [A] -S Addr Rd [A] [Count] A [Data] ... A P -``` - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(b, d) = i2c_block_process_call(pi, h, 10, b'\\x02\\x05\\x00') - -(b, d) = i2c_block_process_call(pi, h, 10, b'abcdr') - -(b, d) = i2c_block_process_call(pi, h, 10, "abracad") - -(b, d) = i2c_block_process_call(pi, h, 10, [2, 5, 16]) -``` -""" -function i2c_block_process_call(self::Pi, handle, reg, data) - # I p1 handle - # I p2 reg - # I p3 len - ## extension ## - # s len data bytes - - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CPK, handle, reg, length(data), data, false)) - if bytes > 0 - data = rxbuf(self, bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Writes data bytes to the specified register of the device -associated with handle . 1-32 bytes may be written. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -data:= the bytes to write. - -``` -S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P -``` - -```julia -i2c_write_i2c_block_data(pi, 4, 5, 'hello') - -i2c_write_i2c_block_data(pi, 4, 5, b'hello') - -i2c_write_i2c_block_data(pi, 5, 0, b'\\x00\\x01\\x22') - -i2c_write_i2c_block_data(pi, 6, 2, [0, 1, 0x22]) -``` -""" -function i2c_write_i2c_block_data(self::Pi, handle, reg, data) - # I p1 handle - # I p2 reg - # I p3 len - ## extension ## - # s len data bytes - if length(data) > 0 - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CWI, handle, reg, length(data), [data])) - else - return 0 - end -end - -""" -Reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -reg:= >=0, the device register. -count:= >0, the number of bytes to read. - -``` -S Addr Wr [A] reg [A] -S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -``` - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(b, d) = i2c_read_i2c_block_data(pi, h, 4, 32) -if b >= 0 -# process data -else -# process read failure -``` -""" -function i2c_read_i2c_block_data(self::Pi, handle, reg, count) - # I p1 handle - # I p2 reg - # I p3 4 - ## extension ## - # I count - extents = IOBuffer() - write(extents, count) - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CRI, handle, reg, 4, extents, false)) - if bytes > 0 - data = rxbuf(self, bytes) - else - data = "" - end - - unlock(self.sl.l) - return bytes, data -end - -""" -Returns count bytes read from the raw device associated -with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -count:= >0, the number of bytes to read. - -``` -S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -``` - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(count, data) = i2c_read_device(pi, h, 12) -``` -""" -function i2c_read_device(self::Pi, handle, count) - # Don't raise exception. Must release lock. - bytes = u2i( - _pigpio_command(self.sl, _PI_CMD_I2CRD, handle, count, false)) - if bytes > 0 - data = rxbuf(self, bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Writes the data bytes to the raw device associated with handle. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -data:= the bytes to write. - -``` -S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P -``` - -```julia -i2c_write_device(pi, h, b"\\x12\\x34\\xA8") - -i2c_write_device(pi, h, b"help") - -i2c_write_device(pi, h, 'help') - -i2c_write_device(pi, h, [23, 56, 231]) -``` -""" -function i2c_write_device(self::Pi, handle, data) - # I p1 handle - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - if length(data) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CWD, handle, 0, length(data), data)) - else - return 0 - end -end - -""" -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of data -which contains the concatenated command codes and associated data. - -handle:= >=0 (as returned by a prior call to [*i2c_open*]). -data:= the concatenated I2C commands, see below - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(count, data) = i2c_zip(pi, h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) -``` - -The following command codes are supported - -Name @ Cmd & Data @ Meaning -End @ 0 @ No more commands -Escape @ 1 @ Next P is two bytes -On @ 2 @ Switch combined flag on -Off @ 3 @ Switch combined flag off -Address @ 4 P @ Set I2C address to P -Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) -Read @ 6 P @ Read P bytes of data -Write @ 7 P ... @ Write P bytes of data - -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -Any read I2C data is concatenated in the returned bytearray. - -``` -Set address 0x53, write 0x32, read 6 bytes -Set address 0x1E, write 0x03, read 6 bytes -Set address 0x68, write 0x1B, read 8 bytes -End - -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -0x00 -``` -""" -function i2c_zip(self::Pi, handle, data) - # I p1 handle - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_I2CZ, handle, 0, length(data), data, false)) - if bytes > 0 - data = self._rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -o baud rates as low as 50 -o repeated starts -o clock stretching -o I2C on any pair of spare GPIO - -SDA:= 0-31 -SCL:= 0-31 -baud:= 50-500000 - -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -NOTE - -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -```julia -h = bb_i2c_open(pi, 4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps -``` -""" -function bb_i2c_open(self::Pi, SDA, SCL, baud=100000) - # I p1 SDA - # I p2 SCL - # I p3 4 - ## extension ## - # I baud - extents = IOBuffer() - write(extents, baud) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_BI2CO, SDA, SCL, 4, extents)) -end - -""" -This function stops bit banging I2C on a pair of GPIO -previously opened with [*bb_i2c_open*]. - -SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] - -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -```julia -bb_i2c_close(pi, SDA) -``` -""" -function bb_i2c_close(self::Pi, SDA) - return _u2i(_pigpio_command(self.sl, _PI_CMD_BI2CC, SDA, 0)) -end - -""" -This function executes a sequence of bit banged I2C operations. -The operations to be performed are specified by the contents -of data which contains the concatenated command codes and -associated data. - -SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) -data:= the concatenated I2C commands, see below - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -```julia -(count, data) = pi.bb_i2c_zip( - h, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) -``` - -The following command codes are supported - -Name @ Cmd & Data @ Meaning -End @ 0 @ No more commands -Escape @ 1 @ Next P is two bytes -Start @ 2 @ Start condition -Stop @ 3 @ Stop condition -Address @ 4 P @ Set I2C address to P -Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) -Read @ 6 P @ Read P bytes of data -Write @ 7 P ... @ Write P bytes of data - -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -No flags are currently defined. - -Any read I2C data is concatenated in the returned bytearray. - -``` -Set address 0x53 -start, write 0x32, (re)start, read 6 bytes, stop -Set address 0x1E -start, write 0x03, (re)start, read 6 bytes, stop -Set address 0x68 -start, write 0x1B, (re)start, read 8 bytes, stop -End - -0x04 0x53 -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 - -0x04 0x1E -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 - -0x04 0x68 -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 - -0x00 -``` -""" -function bb_i2c_zip(self::Pi, SDA, data) - # I p1 SDA - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_BI2CZ, SDA, 0, length(data), [data], false)) - if bytes > 0 - data = self._rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end +""" +Returns a handle (>=0) for the device at the I2C bus address. + +i2c_bus:= >=0. +i2c_address:= 0-0x7F. +i2c_flags:= 0, no flags are currently defined. + +Normally you would only use the [*i2c_**] functions if +you are or will be connecting to the Pi over a network. If +you will always run on the local Pi use the standard SMBus +module instead. + +Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. + +For the SMBus commands the low level transactions are shown +at the end of the function description. The following +abbreviations are used. + +``` +S (1 bit) : Start bit +P (1 bit) : Stop bit +Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. +A, NA (1 bit) : Accept and not accept bit. +Addr (7 bits): I2C 7 bit address. +reg (8 bits): Command byte, which often selects a register. +Data (8 bits): A data byte. +Count (8 bits): A byte defining the length of a block operation. + +[..]: Data sent by the device. +``` + +```julia +h = i2c_open(pi, 1, 0x53) # open device at address 0x53 on bus 1 +``` +""" +function i2c_open(self::Pi, i2c_bus, i2c_address, i2c_flags=0) + # I p1 i2c_bus + # I p2 i2c_addr + # I p3 4 + ## extension ## + # I i2c_flags + extents = [pack("I", i2c_flags)] + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents)) +end + +""" +Closes the I2C device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). + +```julia +i2c_close(pi, h) +``` +""" +function i2c_close(self::Pi, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CC, handle, 0)) +end + +""" +Sends a single bit to the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +bit:= 0 or 1, the value to write. + +SMBus 2.0 5.5.1 - Quick command. +``` +S Addr bit [A] P +``` + +```julia +i2c_write_quick(pi, 0, 1) # send 1 to device 0 +i2c_write_quick(pi, 3, 0) # send 0 to device 3 +``` +""" +function i2c_write_quick(self::Pi, handle, bit) + return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CWQ, handle, bit)) +end + +""" +Sends a single byte to the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +byte_val:= 0-255, the value to write. + +SMBus 2.0 5.5.2 - Send byte. +``` +S Addr Wr [A] byte_val [A] P +``` + +```julia +i2c_write_byte(pi, 1, 17) # send byte 17 to device 1 +i2c_write_byte(pi, 2, 0x23) # send byte 0x23 to device 2 +``` +""" +function i2c_write_byte(self::Pi, handle, byte_val) + return _u2i( + _pigpio_command(self.sl, _PI_CMD_I2CWS, handle, byte_val)) +end + +""" +Reads a single byte from the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). + +SMBus 2.0 5.5.3 - Receive byte. +``` +S Addr Rd [A] [Data] NA P +``` + +```julia +b = i2c_read_byte(pi, 2) # read a byte from device 2 +``` +""" +function i2c_read_byte(self::Pi, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRS, handle, 0)) +end + +""" +Writes a single byte to the specified register of the device +associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +byte_val:= 0-255, the value to write. + +SMBus 2.0 5.5.4 - Write byte. +``` +S Addr Wr [A] reg [A] byte_val [A] P +``` + +```julia +# send byte 0xC5 to reg 2 of device 1 +i2c_write_byte_data(pi, 1, 2, 0xC5) + +# send byte 9 to reg 4 of device 2 +i2c_write_byte_data(pi, 2, 4, 9) +``` +""" +function i2c_write_byte_data(self::Pi, handle, reg, byte_val) + # I p1 handle + # I p2 reg + # I p3 4 + ## extension ## + # I byte_val + extents = IOBuffer + write(extents, byte_val) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CWB, handle, reg, 4, extents)) +end + +""" +Writes a single 16 bit word to the specified register of the +device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +word_val:= 0-65535, the value to write. + +SMBus 2.0 5.5.4 - Write word. +``` +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P +``` + +```julia +# send word 0xA0C5 to reg 5 of device 4 +i2c_write_word_data(pi, 4, 5, 0xA0C5) + +# send word 2 to reg 2 of device 5 +i2c_write_word_data(pi, 5, 2, 23) +``` +""" +function i2c_write_word_data(self::Pi, handle, reg, word_val) + # I p1 handle + # I p2 reg + # I p3 4 + ## extension ## + # I word_val + extents = IOBuffer + write(extents, word_val) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CWW, handle, reg, 4, extents)) +end + +""" +Reads a single byte from the specified register of the device +associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. + +SMBus 2.0 5.5.5 - Read byte. +``` +S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P +``` + +```julia +# read byte from reg 17 of device 2 +b = i2c_read_byte_data(pi, 2, 17) + +# read byte from reg 1 of device 0 +b = i2c_read_byte_data(pi, 0, 1) +``` +""" +function i2c_read_byte_data(self, handle, reg) + return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRB, handle, reg)) +end + +""" +Reads a single 16 bit word from the specified register of the +device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. + +SMBus 2.0 5.5.5 - Read word. +``` +S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P +``` + +```julia +# read word from reg 2 of device 3 +w = i2c_read_word_data(pi, 3, 2) + +# read word from reg 7 of device 2 +w = i2c_read_word_data(pi, 2, 7) +``` +""" +function i2c_read_word_data(self, handle, reg) + return _u2i(_pigpio_command(self.sl, _PI_CMD_I2CRW, handle, reg)) +end + +""" +Writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +word_val:= 0-65535, the value to write. + +SMBus 2.0 5.5.6 - Process call. +``` +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] +S Addr Rd [A] [DataLow] A [DataHigh] NA P +``` + +```julia +r = i2c_process_call(pi, h, 4, 0x1231) +r = i2c_process_call(pi, h, 6, 0) +``` +""" +function i2c_process_call(self, handle, reg, word_val) + # I p1 handle + # I p2 reg + # I p3 4 + ## extension ## + # I word_val + extents = IOBuffer + write(extents, word_val) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CPC, handle, reg, 4, extents)) +end + +""" +Writes up to 32 bytes to the specified register of the device +associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +data:= the bytes to write. + +SMBus 2.0 5.5.7 - Block write. +``` +S Addr Wr [A] reg [A] length(data) [A] data0 [A] data1 [A] ... [A] +datan [A] P +``` + +```julia +i2c_write_block_data(pi, 4, 5, b'hello') + +i2c_write_block_data(pi, 4, 5, "data bytes") + +i2c_write_block_data(pi, 5, 0, b'\\x00\\x01\\x22') + +i2c_write_block_data(pi, 6, 2, [0, 1, 0x22]) +``` +""" +function i2c_write_block_data(self, handle, reg, data) +# I p1 handle +# I p2 reg +# I p3 len +## extension ## +# s len data bytes + if length(data) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CWK, handle, reg, length(data), data)) + else + return 0 + end +end + +""" +Reads a block of up to 32 bytes from the specified register of +the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. + +SMBus 2.0 5.5.7 - Block read. +``` +S Addr Wr [A] reg [A] +S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P +``` + +The amount of returned data is set by the device. + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(b, d) = i2c_read_block_data(pi, h, 10) +if b >= 0 +# process data +else +# process read failure +``` +""" +function i2c_read_block_data(self::Pi, handle, reg) + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command(self.sl, _PI_CMD_I2CRK, handle, reg, false)) + if bytes > 0 + data = rxbuf(bytes) + else + data = "" + end + + unlock(self.sl.l) + return bytes, data +end + +""" +Writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +data:= the bytes to write. + +The SMBus 2.0 documentation states that a minimum of 1 byte may +be sent and a minimum of 1 byte may be received. The total +number of bytes sent/received must be 32 or less. + +SMBus 2.0 5.5.8 - Block write-block read. +``` +S Addr Wr [A] reg [A] length(data) [A] data0 [A] ... datan [A] +S Addr Rd [A] [Count] A [Data] ... A P +``` + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(b, d) = i2c_block_process_call(pi, h, 10, b'\\x02\\x05\\x00') + +(b, d) = i2c_block_process_call(pi, h, 10, b'abcdr') + +(b, d) = i2c_block_process_call(pi, h, 10, "abracad") + +(b, d) = i2c_block_process_call(pi, h, 10, [2, 5, 16]) +``` +""" +function i2c_block_process_call(self::Pi, handle, reg, data) + # I p1 handle + # I p2 reg + # I p3 len + ## extension ## + # s len data bytes + + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CPK, handle, reg, length(data), data, false)) + if bytes > 0 + data = rxbuf(self, bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Writes data bytes to the specified register of the device +associated with handle . 1-32 bytes may be written. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +data:= the bytes to write. + +``` +S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P +``` + +```julia +i2c_write_i2c_block_data(pi, 4, 5, 'hello') + +i2c_write_i2c_block_data(pi, 4, 5, b'hello') + +i2c_write_i2c_block_data(pi, 5, 0, b'\\x00\\x01\\x22') + +i2c_write_i2c_block_data(pi, 6, 2, [0, 1, 0x22]) +``` +""" +function i2c_write_i2c_block_data(self::Pi, handle, reg, data) + # I p1 handle + # I p2 reg + # I p3 len + ## extension ## + # s len data bytes + if length(data) > 0 + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CWI, handle, reg, length(data), [data])) + else + return 0 + end +end + +""" +Reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +reg:= >=0, the device register. +count:= >0, the number of bytes to read. + +``` +S Addr Wr [A] reg [A] +S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P +``` + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(b, d) = i2c_read_i2c_block_data(pi, h, 4, 32) +if b >= 0 +# process data +else +# process read failure +``` +""" +function i2c_read_i2c_block_data(self::Pi, handle, reg, count) + # I p1 handle + # I p2 reg + # I p3 4 + ## extension ## + # I count + extents = IOBuffer() + write(extents, count) + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CRI, handle, reg, 4, extents, false)) + if bytes > 0 + data = rxbuf(self, bytes) + else + data = "" + end + + unlock(self.sl.l) + return bytes, data +end + +""" +Returns count bytes read from the raw device associated +with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +count:= >0, the number of bytes to read. + +``` +S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P +``` + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(count, data) = i2c_read_device(pi, h, 12) +``` +""" +function i2c_read_device(self::Pi, handle, count) + # Don't raise exception. Must release lock. + bytes = u2i( + _pigpio_command(self.sl, _PI_CMD_I2CRD, handle, count, false)) + if bytes > 0 + data = rxbuf(self, bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Writes the data bytes to the raw device associated with handle. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +data:= the bytes to write. + +``` +S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P +``` + +```julia +i2c_write_device(pi, h, b"\\x12\\x34\\xA8") + +i2c_write_device(pi, h, b"help") + +i2c_write_device(pi, h, 'help') + +i2c_write_device(pi, h, [23, 56, 231]) +``` +""" +function i2c_write_device(self::Pi, handle, data) + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + if length(data) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CWD, handle, 0, length(data), data)) + else + return 0 + end +end + +""" +This function executes a sequence of I2C operations. The +operations to be performed are specified by the contents of data +which contains the concatenated command codes and associated data. + +handle:= >=0 (as returned by a prior call to [*i2c_open*]). +data:= the concatenated I2C commands, see below + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(count, data) = i2c_zip(pi, h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) +``` + +The following command codes are supported + +Name @ Cmd & Data @ Meaning +End @ 0 @ No more commands +Escape @ 1 @ Next P is two bytes +On @ 2 @ Switch combined flag on +Off @ 3 @ Switch combined flag off +Address @ 4 P @ Set I2C address to P +Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) +Read @ 6 P @ Read P bytes of data +Write @ 7 P ... @ Write P bytes of data + +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. + +Any read I2C data is concatenated in the returned bytearray. + +``` +Set address 0x53, write 0x32, read 6 bytes +Set address 0x1E, write 0x03, read 6 bytes +Set address 0x68, write 0x1B, read 8 bytes +End + +0x04 0x53 0x07 0x01 0x32 0x06 0x06 +0x04 0x1E 0x07 0x01 0x03 0x06 0x06 +0x04 0x68 0x07 0x01 0x1B 0x06 0x08 +0x00 +``` +""" +function i2c_zip(self::Pi, handle, data) + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_I2CZ, handle, 0, length(data), data, false)) + if bytes > 0 + data = self._rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. + +Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. + +o baud rates as low as 50 +o repeated starts +o clock stretching +o I2C on any pair of spare GPIO + +SDA:= 0-31 +SCL:= 0-31 +baud:= 50-500000 + +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. + +NOTE + +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. +As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + +```julia +h = bb_i2c_open(pi, 4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps +``` +""" +function bb_i2c_open(self::Pi, SDA, SCL, baud=100000) + # I p1 SDA + # I p2 SCL + # I p3 4 + ## extension ## + # I baud + extents = IOBuffer() + write(extents, baud) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_BI2CO, SDA, SCL, 4, extents)) +end + +""" +This function stops bit banging I2C on a pair of GPIO +previously opened with [*bb_i2c_open*]. + +SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] + +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. + +```julia +bb_i2c_close(pi, SDA) +``` +""" +function bb_i2c_close(self::Pi, SDA) + return _u2i(_pigpio_command(self.sl, _PI_CMD_BI2CC, SDA, 0)) +end + +""" +This function executes a sequence of bit banged I2C operations. +The operations to be performed are specified by the contents +of data which contains the concatenated command codes and +associated data. + +SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) +data:= the concatenated I2C commands, see below + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +```julia +(count, data) = pi.bb_i2c_zip( + h, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) +``` + +The following command codes are supported + +Name @ Cmd & Data @ Meaning +End @ 0 @ No more commands +Escape @ 1 @ Next P is two bytes +Start @ 2 @ Start condition +Stop @ 3 @ Stop condition +Address @ 4 P @ Set I2C address to P +Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) +Read @ 6 P @ Read P bytes of data +Write @ 7 P ... @ Write P bytes of data + +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +No flags are currently defined. + +Any read I2C data is concatenated in the returned bytearray. + +``` +Set address 0x53 +start, write 0x32, (re)start, read 6 bytes, stop +Set address 0x1E +start, write 0x03, (re)start, read 6 bytes, stop +Set address 0x68 +start, write 0x1B, (re)start, read 8 bytes, stop +End + +0x04 0x53 +0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 + +0x04 0x1E +0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 + +0x04 0x68 +0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 + +0x00 +``` +""" +function bb_i2c_zip(self::Pi, SDA, data) + # I p1 SDA + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_BI2CZ, SDA, 0, length(data), [data], false)) + if bytes > 0 + data = self._rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end From 9e7cb9fc104ea626a64bbcbc63cd8df53531f4b2 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:05:30 +0200 Subject: [PATCH 16/51] dos2unix --- src/spiSerial.jl | 900 +++++++++++++++++++-------------------- src/wave.jl | 1060 +++++++++++++++++++++++----------------------- 2 files changed, 980 insertions(+), 980 deletions(-) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 5952f21..8530d83 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -1,450 +1,450 @@ -""" -Returns a handle for the SPI device on channel. Data will be -transferred at baud bits per second. The flags may be used to -modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -An auxiliary SPI device is available on all models but the -A and B and may be selected by setting the A bit in the -flags. The auxiliary device has 3 chip selects and a -selectable word size in bits. - -spi_channel:= 0-1 (0-2 for the auxiliary SPI device). - baud:= 32K-125M (values above 30M are unlikely to work). -spi_flags:= see below. - -Normally you would only use the [*spi_**] functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard SPI -module instead. - -spi_flags consists of the least significant 22 bits. - -. . -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -. . - -mm defines the SPI mode. - -WARNING: modes 1 and 3 do not appear to work on -the auxiliary device. - -. . -Mode POL PHA -0 0 0 -1 0 1 -2 1 0 -3 1 1 -. . - -px is 0 if CEx is active low (default) and 1 for active high. - -ux is 0 if the CEx GPIO is reserved for SPI (default) -and 1 otherwise. - -A is 0 for the standard SPI device, 1 for the auxiliary SPI. - -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. -Standard SPI device only. - -nnnn defines the number of bytes (0-15) to write before -switching the MOSI line to MISO to read data. This field -is ignored if W is not set. Standard SPI device only. - -T is 1 if the least significant bit is transmitted on MOSI -first, the default (0) shifts the most significant bit out -first. Auxiliary SPI device only. - -R is 1 if the least significant bit is received on MISO -first, the default (0) receives the most significant bit -first. Auxiliary SPI device only. - -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI device only. - -The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -For bits 1-8 there will be one byte per character. -For bits 9-16 there will be two bytes per character. -For bits 17-32 there will be four bytes per character. - -E.g. 32 12-bit words will be transferred in 64 bytes. - -The other bits in flags should be set to zero. - -... -# open SPI device on channel 1 in mode 3 at 50000 bits per second - -h = spi_open(pi, 1, 50000, 3) -... -""" -function spi_open(self::Pi, spi_channel, baud, spi_flags=0) - # I p1 spi_channel - # I p2 baud - # I p3 4 - ## extension ## - # I spi_flags - extents=IOBuffer() - write(extents, spi_flags::Cint) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SPIO, spi_channel, baud, 4, extents)) -end - -""" -Closes the SPI device associated with handle. - -handle:= >=0 (as returned by a prior call to [*spi_open*]). - -... -spi_close(pi, h) -... -""" -function spi_close(self, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SPIC, handle, 0)) -end - -""" -Reads count bytes from the SPI device associated with handle. - -handle:= >=0 (as returned by a prior call to [*spi_open*]). -count:= >0, the number of bytes to read. - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -... -(b, d) = spi_read(pi, h, 60) # read 60 bytes from device h -if b == 60 -# process read data -else -# error path -... -""" -function spi_read(self::Pi, handle, count) - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command( - self.sl, _PI_CMD_SPIR, handle, count, false)) - if bytes > 0 - data = rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Writes the data bytes to the SPI device associated with handle. - -handle:= >=0 (as returned by a prior call to [*spi_open*]). -data:= the bytes to write. - -... -spi_write(pi, 0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 - -spi_write(pi, 0, b'defgh') # write 5 bytes to device 0 - -spi_write(pi, 0, "def") # write 3 bytes to device 0 - -spi_write(pi, 1, [2, 192, 128]) # write 3 bytes to device 1 -... -""" -function spi_write(self::Pi, handle, data) - # I p1 handle - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SPIW, handle, 0, length(data), data)) -end - -""" -Writes the data bytes to the SPI device associated with handle, -returning the data bytes read from the device. - -handle:= >=0 (as returned by a prior call to [*spi_open*]). -data:= the bytes to write. - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -... -(count, rx_data) = spi_xfer(pi, h, b'\\x01\\x80\\x00') - -(count, rx_data) = spi_xfer(pi, h, [1, 128, 0]) - -(count, rx_data) = spi_xfer(pi, h, b"hello") - -(count, rx_data) = spi_xfer(pi, h, "hello") -... -""" -function spi_xfer(self::Pi, handle, data) - # I p1 handle - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - - # Don't raise exception. Must release lock. - bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SPIX, handle, 0, length(data), data, false)) - if bytes > 0 - data = rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Returns a handle for the serial tty device opened -at baud bits per second. - -tty:= the serial device to open. -baud:= baud rate in bits per second, see below. -ser_flags:= 0, no flags are currently defined. - -Normally you would only use the [*serial_**] functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard serial -module instead. - -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -... -h1 = serial_open(pi, "/dev/ttyAMA0", 300) - -h2 = serial_open(pi, "/dev/ttyUSB1", 19200, 0) -... -""" -function serial_open(self::Pi, tty, baud, ser_flags=0) - # I p1 baud - # I p2 ser_flags - # I p3 len - ## extension ## - # s len data bytes - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SERO, baud, ser_flags, length(tty), [tty])) -end - -""" -Closes the serial device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). - -... -serial_close(pi, h1) -... -""" -function serial_close(self::Pi, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SERC, handle, 0)) -end - -""" -Returns a single byte from the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). - -... -b = serial_read_byte(pi, h1) -... -""" -function serial_read_byte(self::Pi, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SERRB, handle, 0)) -end - -""" -Writes a single byte to the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). -byte_val:= 0-255, the value to write. - -... -serial_write_byte(pi, h1, 23) - -serial_write_byte(h1, ord(pi, 'Z')) -... -""" -function serial_write_byte(self::Pi, handle, byte_val) - return _u2i( - _pigpio_command(self.sl, _PI_CMD_SERWB, handle, byte_val)) -end - -""" -Reads up to count bytes from the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). -count:= >0, the number of bytes to read. - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -... -(b, d) = serial_read(pi, h2, 100) -if b > 0 -# process read data -... -""" -function serial_read(self::Pi, handle, count) - # Don't raise exception. Must release lock. - bytes = u2i( - _pigpio_command(self.sl, _PI_CMD_SERR, handle, count, false)) - if bytes > 0 - data = rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Writes the data bytes to the device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). -data:= the bytes to write. - -... -serial_write(pi, h1, b'\\x02\\x03\\x04') - -serial_write(pi, h2, b'help') - -serial_write(pi, h2, "hello") - -serial_write(pi, h1, [2, 3, 4]) -... -""" -function serial_write(self::Pi, handle, data) - # I p1 handle - # I p2 0 - # I p3 len - ## extension ## - # s len data bytes - - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SERW, handle, 0, length(data), [data])) -end - -""" -Returns the number of bytes available to be read from the -device associated with handle. - -handle:= >=0 (as returned by a prior call to [*serial_open*]). - -... -rdy = serial_data_available(pi, h1) - -if rdy > 0 -(b, d) = serial_read(pi, h1, rdy) -... -""" -function serial_data_available(self::Pi, handle) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SERDA, handle, 0)) -end - -""" -Opens a GPIO for bit bang reading of serial data. - -user_gpio:= 0-31, the GPIO to use. -baud:= 50-250000, the baud rate. -bb_bits:= 1-32, the number of bits per word, default 8. - -The serial data is held in a cyclic buffer and is read using -[*bb_serial_read*]. - -It is the caller's responsibility to read data from the cyclic -buffer in a timely fashion. - -... -status = bb_serial_read_open(pi, 4, 19200) -status = bb_serial_read_open(pi, 17, 9600) -... -""" -function bb_serial_read_open(self, user_gpio, baud, bb_bits=8) - # pigpio message format - - # I p1 user_gpio - # I p2 baud - # I p3 4 - ## extension ## - # I bb_bits - extents = IOBuffer() - write(extents, bb_bits::Cuint) - return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SLRO, user_gpio, baud, 4, extents)) -end - -""" -Returns data from the bit bang serial cyclic buffer. - -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - -The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). - -The bytes returned for each character depend upon the number of -data bits [*bb_bits*] specified in the [*bb_serial_read_open*] -command. - -For [*bb_bits*] 1-8 there will be one byte per character. -For [*bb_bits*] 9-16 there will be two bytes per character. -For [*bb_bits*] 17-32 there will be four bytes per character. - -... -(count, data) = bb_serial_read(pi, 4) -... -""" -function bb_serial_read(self, user_gpio) - # Don't raise exception. Must release lock. - bytes = u2i( - _pigpio_command(self.sl, _PI_CMD_SLR, user_gpio, 10000, false)) - if bytes > 0 - data = self._rxbuf(bytes) - else - data = "" - end - unlock(self.sl.l) - return bytes, data -end - -""" -Closes a GPIO for bit bang reading of serial data. - -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - -... -status = bb_serial_read_close(pi, 17) -... -""" -function bb_serial_read_close(self, user_gpio) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRC, user_gpio, 0)) -end - -""" -Invert serial logic. - -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) -invert:= 0-1 (1 invert, 0 normal) - -... -status = bb_serial_invert(pi, 17, 1) -... -""" -function bb_serial_invert(self, user_gpio, invert) - return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRI, user_gpio, invert)) -end +""" +Returns a handle for the SPI device on channel. Data will be +transferred at baud bits per second. The flags may be used to +modify the default behaviour of 4-wire operation, mode 0, +active low chip select. + +An auxiliary SPI device is available on all models but the +A and B and may be selected by setting the A bit in the +flags. The auxiliary device has 3 chip selects and a +selectable word size in bits. + +spi_channel:= 0-1 (0-2 for the auxiliary SPI device). + baud:= 32K-125M (values above 30M are unlikely to work). +spi_flags:= see below. + +Normally you would only use the [*spi_**] functions if +you are or will be connecting to the Pi over a network. If +you will always run on the local Pi use the standard SPI +module instead. + +spi_flags consists of the least significant 22 bits. + +. . +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m +. . + +mm defines the SPI mode. + +WARNING: modes 1 and 3 do not appear to work on +the auxiliary device. + +. . +Mode POL PHA +0 0 0 +1 0 1 +2 1 0 +3 1 1 +. . + +px is 0 if CEx is active low (default) and 1 for active high. + +ux is 0 if the CEx GPIO is reserved for SPI (default) +and 1 otherwise. + +A is 0 for the standard SPI device, 1 for the auxiliary SPI. + +W is 0 if the device is not 3-wire, 1 if the device is 3-wire. +Standard SPI device only. + +nnnn defines the number of bytes (0-15) to write before +switching the MOSI line to MISO to read data. This field +is ignored if W is not set. Standard SPI device only. + +T is 1 if the least significant bit is transmitted on MOSI +first, the default (0) shifts the most significant bit out +first. Auxiliary SPI device only. + +R is 1 if the least significant bit is received on MISO +first, the default (0) receives the most significant bit +first. Auxiliary SPI device only. + +bbbbbb defines the word size in bits (0-32). The default (0) +sets 8 bits per word. Auxiliary SPI device only. + +The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. + +For bits 1-8 there will be one byte per character. +For bits 9-16 there will be two bytes per character. +For bits 17-32 there will be four bytes per character. + +E.g. 32 12-bit words will be transferred in 64 bytes. + +The other bits in flags should be set to zero. + +... +# open SPI device on channel 1 in mode 3 at 50000 bits per second + +h = spi_open(pi, 1, 50000, 3) +... +""" +function spi_open(self::Pi, spi_channel, baud, spi_flags=0) + # I p1 spi_channel + # I p2 baud + # I p3 4 + ## extension ## + # I spi_flags + extents=IOBuffer() + write(extents, spi_flags::Cint) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SPIO, spi_channel, baud, 4, extents)) +end + +""" +Closes the SPI device associated with handle. + +handle:= >=0 (as returned by a prior call to [*spi_open*]). + +... +spi_close(pi, h) +... +""" +function spi_close(self, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SPIC, handle, 0)) +end + +""" +Reads count bytes from the SPI device associated with handle. + +handle:= >=0 (as returned by a prior call to [*spi_open*]). +count:= >0, the number of bytes to read. + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +... +(b, d) = spi_read(pi, h, 60) # read 60 bytes from device h +if b == 60 +# process read data +else +# error path +... +""" +function spi_read(self::Pi, handle, count) + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command( + self.sl, _PI_CMD_SPIR, handle, count, false)) + if bytes > 0 + data = rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Writes the data bytes to the SPI device associated with handle. + +handle:= >=0 (as returned by a prior call to [*spi_open*]). +data:= the bytes to write. + +... +spi_write(pi, 0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 + +spi_write(pi, 0, b'defgh') # write 5 bytes to device 0 + +spi_write(pi, 0, "def") # write 3 bytes to device 0 + +spi_write(pi, 1, [2, 192, 128]) # write 3 bytes to device 1 +... +""" +function spi_write(self::Pi, handle, data) + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SPIW, handle, 0, length(data), data)) +end + +""" +Writes the data bytes to the SPI device associated with handle, +returning the data bytes read from the device. + +handle:= >=0 (as returned by a prior call to [*spi_open*]). +data:= the bytes to write. + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +... +(count, rx_data) = spi_xfer(pi, h, b'\\x01\\x80\\x00') + +(count, rx_data) = spi_xfer(pi, h, [1, 128, 0]) + +(count, rx_data) = spi_xfer(pi, h, b"hello") + +(count, rx_data) = spi_xfer(pi, h, "hello") +... +""" +function spi_xfer(self::Pi, handle, data) + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SPIX, handle, 0, length(data), data, false)) + if bytes > 0 + data = rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Returns a handle for the serial tty device opened +at baud bits per second. + +tty:= the serial device to open. +baud:= baud rate in bits per second, see below. +ser_flags:= 0, no flags are currently defined. + +Normally you would only use the [*serial_**] functions if +you are or will be connecting to the Pi over a network. If +you will always run on the local Pi use the standard serial +module instead. + +The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. + +... +h1 = serial_open(pi, "/dev/ttyAMA0", 300) + +h2 = serial_open(pi, "/dev/ttyUSB1", 19200, 0) +... +""" +function serial_open(self::Pi, tty, baud, ser_flags=0) + # I p1 baud + # I p2 ser_flags + # I p3 len + ## extension ## + # s len data bytes + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SERO, baud, ser_flags, length(tty), [tty])) +end + +""" +Closes the serial device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). + +... +serial_close(pi, h1) +... +""" +function serial_close(self::Pi, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SERC, handle, 0)) +end + +""" +Returns a single byte from the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). + +... +b = serial_read_byte(pi, h1) +... +""" +function serial_read_byte(self::Pi, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SERRB, handle, 0)) +end + +""" +Writes a single byte to the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). +byte_val:= 0-255, the value to write. + +... +serial_write_byte(pi, h1, 23) + +serial_write_byte(h1, ord(pi, 'Z')) +... +""" +function serial_write_byte(self::Pi, handle, byte_val) + return _u2i( + _pigpio_command(self.sl, _PI_CMD_SERWB, handle, byte_val)) +end + +""" +Reads up to count bytes from the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). +count:= >0, the number of bytes to read. + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +... +(b, d) = serial_read(pi, h2, 100) +if b > 0 +# process read data +... +""" +function serial_read(self::Pi, handle, count) + # Don't raise exception. Must release lock. + bytes = u2i( + _pigpio_command(self.sl, _PI_CMD_SERR, handle, count, false)) + if bytes > 0 + data = rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Writes the data bytes to the device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). +data:= the bytes to write. + +... +serial_write(pi, h1, b'\\x02\\x03\\x04') + +serial_write(pi, h2, b'help') + +serial_write(pi, h2, "hello") + +serial_write(pi, h1, [2, 3, 4]) +... +""" +function serial_write(self::Pi, handle, data) + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SERW, handle, 0, length(data), [data])) +end + +""" +Returns the number of bytes available to be read from the +device associated with handle. + +handle:= >=0 (as returned by a prior call to [*serial_open*]). + +... +rdy = serial_data_available(pi, h1) + +if rdy > 0 +(b, d) = serial_read(pi, h1, rdy) +... +""" +function serial_data_available(self::Pi, handle) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SERDA, handle, 0)) +end + +""" +Opens a GPIO for bit bang reading of serial data. + +user_gpio:= 0-31, the GPIO to use. +baud:= 50-250000, the baud rate. +bb_bits:= 1-32, the number of bits per word, default 8. + +The serial data is held in a cyclic buffer and is read using +[*bb_serial_read*]. + +It is the caller's responsibility to read data from the cyclic +buffer in a timely fashion. + +... +status = bb_serial_read_open(pi, 4, 19200) +status = bb_serial_read_open(pi, 17, 9600) +... +""" +function bb_serial_read_open(self, user_gpio, baud, bb_bits=8) + # pigpio message format + + # I p1 user_gpio + # I p2 baud + # I p3 4 + ## extension ## + # I bb_bits + extents = IOBuffer() + write(extents, bb_bits::Cuint) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SLRO, user_gpio, baud, 4, extents)) +end + +""" +Returns data from the bit bang serial cyclic buffer. + +user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) + +The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). + +The bytes returned for each character depend upon the number of +data bits [*bb_bits*] specified in the [*bb_serial_read_open*] +command. + +For [*bb_bits*] 1-8 there will be one byte per character. +For [*bb_bits*] 9-16 there will be two bytes per character. +For [*bb_bits*] 17-32 there will be four bytes per character. + +... +(count, data) = bb_serial_read(pi, 4) +... +""" +function bb_serial_read(self, user_gpio) + # Don't raise exception. Must release lock. + bytes = u2i( + _pigpio_command(self.sl, _PI_CMD_SLR, user_gpio, 10000, false)) + if bytes > 0 + data = self._rxbuf(bytes) + else + data = "" + end + unlock(self.sl.l) + return bytes, data +end + +""" +Closes a GPIO for bit bang reading of serial data. + +user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) + +... +status = bb_serial_read_close(pi, 17) +... +""" +function bb_serial_read_close(self, user_gpio) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRC, user_gpio, 0)) +end + +""" +Invert serial logic. + +user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) +invert:= 0-1 (1 invert, 0 normal) + +... +status = bb_serial_invert(pi, 17, 1) +... +""" +function bb_serial_invert(self, user_gpio, invert) + return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRI, user_gpio, invert)) +end diff --git a/src/wave.jl b/src/wave.jl index 5ef9be1..93a7b51 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -1,530 +1,530 @@ -""" -Clears all waveforms and any data added by calls to the -[*wave_add_**] functions. - -... -wave_clear(pi, ) -... -""" -function wave_clear(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCLR, 0, 0)) -end - -""" -Starts a new empty waveform. - -You would not normally need to call this function as it is -automatically called after a waveform is created with the -[*wave_create*] function. - -... -wave_add_new(pi, ) -... -""" -function wave_add_new(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVNEW, 0, 0)) -end - -""" -Adds a list of pulses to the current waveform. - -pulses:= list of pulses to add to the waveform. - -Returns the new total number of pulses in the current waveform. - -The pulses are interleaved in time order within the existing -waveform (if any). - -Merging allows the waveform to be built in parts, that is the -settings for GPIO#1 can be added, and then GPIO#2 etc. - -If the added waveform is intended to start after or within -the existing waveform then the first pulse should consist -solely of a delay. - -... -G1=4 -G2=24 - -set_mode(pi, G1, pigpio.OUTPUT) -set_mode(pi, G2, pigpio.OUTPUT) - -flash_500=[] # flash every 500 ms -flash_100=[] # flash every 100 ms - -# ON OFF DELAY - -flash_500.append(pigpio.pulse(1<=0) if OK, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - -The data provided by the [*wave_add_**] functions is consumed by -this function. - -As many waveforms may be created as there is space available. -The wave id is passed to [*wave_send_**] to specify the waveform -to transmit. - -Normal usage would be - -Step 1. [*wave_clear*] to clear all waveforms and added data. - -Step 2. [*wave_add_**] calls to supply the waveform data. - -Step 3. [*wave_create*] to create the waveform and get a unique id - -Repeat steps 2 and 3 as needed. - -Step 4. [*wave_send_**] with the id of the waveform to transmit. - -A waveform comprises one or more pulses. - -A pulse specifies - -1) the GPIO to be switched on at the start of the pulse. -2) the GPIO to be switched off at the start of the pulse. -3) the delay in microseconds before the next pulse. - -Any or all the fields can be zero. It doesn't make any sense -to set all the fields to zero (the pulse will be ignored). - -When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. - -... -wid = wave_create(pi, ) -... -""" -function wave_create(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) -end - -""" -This function deletes the waveform with id wave_id. - -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - -Wave ids are allocated in order, 0, 1, 2, etc. - -... -wave_delete(pi, 6) # delete waveform with id 6 - -wave_delete(pi, 0) # delete waveform with id 0 -... -""" -function wave_delete(self::Pi, wave_id) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVDEL, wave_id, 0)) -end - -""" -This function is deprecated and has been removed. - -Use [*wave_create*]/[*wave_send_**] instead. -""" -function wave_tx_start(self::Pi) # DEPRECATED - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0)) -end - -""" -This function is deprecated and has beeen removed. - -Use [*wave_create*]/[*wave_send_**] instead. -""" -function wave_tx_repeat(self::Pi) # DEPRECATED - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0)) -end - -""" -Transmits the waveform with id wave_id. The waveform is sent -once. - -NOTE: Any hardware PWM started by [*hardware_PWM*] will -be cancelled. - -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - -Returns the number of DMA control blocks used in the waveform. - -... -cbs = wave_send_once(pi, wid) -... -""" -function wave_send_once(self::Pi, wave_id) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTX, wave_id, 0)) -end - -""" -Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to [*wave_send_**] -is made. - -NOTE: Any hardware PWM started by [*hardware_PWM*] will -be cancelled. - -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - -Returns the number of DMA control blocks used in the waveform. - -... -cbs = wave_send_repeat(pi, wid) -... -""" -function wave_send_repeat(self::Pi, wave_id) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXR, wave_id, 0)) -end - -""" -Transmits the waveform with id wave_id using mode mode. - -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). -mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, - WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. - -WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. - -WAVE_MODE_REPEAT same as [*wave_send_repeat*]. - -WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries -to sync with the previous waveform. - -WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries -to sync with the previous waveform. - -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -NOTE: Any hardware PWM started by [*hardware_PWM*] will -be cancelled. - -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - -Returns the number of DMA control blocks used in the waveform. - -... -cbs = wave_send_using_mode(pi, wid, WAVE_MODE_REPEAT_SYNC) -... -""" -function wave_send_using_mode(self::Pi, wave_id, mode) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXM, wave_id, mode)) -end - -""" -Returns the id of the waveform currently being -transmitted. - -Returns the waveform id or one of the following special -values - -WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. - -... -wid = wave_tx_at(pi, ) -... -""" -function wave_tx_at(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTAT, 0, 0)) -end - -""" -Returns 1 if a waveform is currently being transmitted, -otherwise 0. - -... -wave_send_once(pi, 0) # send first waveform - -while wave_tx_busy(pi, ): # wait for waveform to be sent -time.sleep(0.1) - -wave_send_once(pi, 1) # send next waveform -... -""" -function wave_tx_busy(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVBSY, 0, 0)) -end - -""" -Stops the transmission of the current waveform. - -This function is intended to stop a waveform started with -wave_send_repeat. - -... -wave_send_repeat(pi, 3) - -time.sleep(5) - -wave_tx_stop(pi, ) -... -""" -function wave_tx_stop(self::Pi) - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVHLT, 0, 0)) -end - -""" -This function transmits a chain of waveforms. - -NOTE: Any hardware PWM started by [*hardware_PWM*] -will be cancelled. - -The waves to be transmitted are specified by the contents -of data which contains an ordered list of [*wave_id*]s -and optional command codes and related data. - -Returns 0 if OK, otherwise PI_CHAIN_NESTING, -PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, -PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, -or PI_BAD_WAVE_ID. - -Each wave is transmitted in the order specified. A wave -may occur multiple times per chain. - -A blocks of waves may be transmitted multiple times by -using the loop commands. The block is bracketed by loop -start and end commands. Loops may be nested. - -Delays between waves may be added with the delay command. - -The following command codes are supported - -Name @ Cmd & Data @ Meaning -Loop Start @ 255 0 @ Identify start of a wave block -Loop Repeat @ 255 1 x y @ loop x + y*256 times -Delay @ 255 2 x y @ delay x + y*256 microseconds -Loop Forever @ 255 3 @ loop forever - -If present Loop Forever must be the last entry in the chain. - -The code is currently dimensioned to support a chain with -roughly 600 entries and 20 loop counters. - -... -#!/usr/bin/env python - -import time -import pigpio - -WAVES=5 -GPIO=4 - -wid=[0]*WAVES - -pi = pigpio.pi() # Connect to local Pi. - -set_mode(pi, GPIO, pigpio.OUTPUT); - -for i in range(WAVES) -pi.wave_add_generic([ -pigpio.pulse(1<=0) if OK, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +The data provided by the [*wave_add_**] functions is consumed by +this function. + +As many waveforms may be created as there is space available. +The wave id is passed to [*wave_send_**] to specify the waveform +to transmit. + +Normal usage would be + +Step 1. [*wave_clear*] to clear all waveforms and added data. + +Step 2. [*wave_add_**] calls to supply the waveform data. + +Step 3. [*wave_create*] to create the waveform and get a unique id + +Repeat steps 2 and 3 as needed. + +Step 4. [*wave_send_**] with the id of the waveform to transmit. + +A waveform comprises one or more pulses. + +A pulse specifies + +1) the GPIO to be switched on at the start of the pulse. +2) the GPIO to be switched off at the start of the pulse. +3) the delay in microseconds before the next pulse. + +Any or all the fields can be zero. It doesn't make any sense +to set all the fields to zero (the pulse will be ignored). + +When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. + +... +wid = wave_create(pi, ) +... +""" +function wave_create(self::Pi) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) +end + +""" +This function deletes the waveform with id wave_id. + +wave_id:= >=0 (as returned by a prior call to [*wave_create*]). + +Wave ids are allocated in order, 0, 1, 2, etc. + +... +wave_delete(pi, 6) # delete waveform with id 6 + +wave_delete(pi, 0) # delete waveform with id 0 +... +""" +function wave_delete(self::Pi, wave_id) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVDEL, wave_id, 0)) +end + +""" +This function is deprecated and has been removed. + +Use [*wave_create*]/[*wave_send_**] instead. +""" +function wave_tx_start(self::Pi) # DEPRECATED + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0)) +end + +""" +This function is deprecated and has beeen removed. + +Use [*wave_create*]/[*wave_send_**] instead. +""" +function wave_tx_repeat(self::Pi) # DEPRECATED + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0)) +end + +""" +Transmits the waveform with id wave_id. The waveform is sent +once. + +NOTE: Any hardware PWM started by [*hardware_PWM*] will +be cancelled. + +wave_id:= >=0 (as returned by a prior call to [*wave_create*]). + +Returns the number of DMA control blocks used in the waveform. + +... +cbs = wave_send_once(pi, wid) +... +""" +function wave_send_once(self::Pi, wave_id) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTX, wave_id, 0)) +end + +""" +Transmits the waveform with id wave_id. The waveform repeats +until wave_tx_stop is called or another call to [*wave_send_**] +is made. + +NOTE: Any hardware PWM started by [*hardware_PWM*] will +be cancelled. + +wave_id:= >=0 (as returned by a prior call to [*wave_create*]). + +Returns the number of DMA control blocks used in the waveform. + +... +cbs = wave_send_repeat(pi, wid) +... +""" +function wave_send_repeat(self::Pi, wave_id) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXR, wave_id, 0)) +end + +""" +Transmits the waveform with id wave_id using mode mode. + +wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, + WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. + +WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. + +WAVE_MODE_REPEAT same as [*wave_send_repeat*]. + +WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries +to sync with the previous waveform. + +WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries +to sync with the previous waveform. + +WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. + +NOTE: Any hardware PWM started by [*hardware_PWM*] will +be cancelled. + +wave_id:= >=0 (as returned by a prior call to [*wave_create*]). + +Returns the number of DMA control blocks used in the waveform. + +... +cbs = wave_send_using_mode(pi, wid, WAVE_MODE_REPEAT_SYNC) +... +""" +function wave_send_using_mode(self::Pi, wave_id, mode) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXM, wave_id, mode)) +end + +""" +Returns the id of the waveform currently being +transmitted. + +Returns the waveform id or one of the following special +values + +WAVE_NOT_FOUND (9998) - transmitted wave not found. +NO_TX_WAVE (9999) - no wave being transmitted. + +... +wid = wave_tx_at(pi, ) +... +""" +function wave_tx_at(self::Pi) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTAT, 0, 0)) +end + +""" +Returns 1 if a waveform is currently being transmitted, +otherwise 0. + +... +wave_send_once(pi, 0) # send first waveform + +while wave_tx_busy(pi, ): # wait for waveform to be sent +time.sleep(0.1) + +wave_send_once(pi, 1) # send next waveform +... +""" +function wave_tx_busy(self::Pi) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVBSY, 0, 0)) +end + +""" +Stops the transmission of the current waveform. + +This function is intended to stop a waveform started with +wave_send_repeat. + +... +wave_send_repeat(pi, 3) + +time.sleep(5) + +wave_tx_stop(pi, ) +... +""" +function wave_tx_stop(self::Pi) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVHLT, 0, 0)) +end + +""" +This function transmits a chain of waveforms. + +NOTE: Any hardware PWM started by [*hardware_PWM*] +will be cancelled. + +The waves to be transmitted are specified by the contents +of data which contains an ordered list of [*wave_id*]s +and optional command codes and related data. + +Returns 0 if OK, otherwise PI_CHAIN_NESTING, +PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, +PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, +or PI_BAD_WAVE_ID. + +Each wave is transmitted in the order specified. A wave +may occur multiple times per chain. + +A blocks of waves may be transmitted multiple times by +using the loop commands. The block is bracketed by loop +start and end commands. Loops may be nested. + +Delays between waves may be added with the delay command. + +The following command codes are supported + +Name @ Cmd & Data @ Meaning +Loop Start @ 255 0 @ Identify start of a wave block +Loop Repeat @ 255 1 x y @ loop x + y*256 times +Delay @ 255 2 x y @ delay x + y*256 microseconds +Loop Forever @ 255 3 @ loop forever + +If present Loop Forever must be the last entry in the chain. + +The code is currently dimensioned to support a chain with +roughly 600 entries and 20 loop counters. + +... +#!/usr/bin/env python + +import time +import pigpio + +WAVES=5 +GPIO=4 + +wid=[0]*WAVES + +pi = pigpio.pi() # Connect to local Pi. + +set_mode(pi, GPIO, pigpio.OUTPUT); + +for i in range(WAVES) +pi.wave_add_generic([ +pigpio.pulse(1< Date: Mon, 9 Sep 2024 19:11:16 +0200 Subject: [PATCH 17/51] use markdown code fences --- src/spiSerial.jl | 64 ++++++++++++++++++++-------------------- src/wave.jl | 76 ++++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 8530d83..b351b58 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -75,11 +75,11 @@ E.g. 32 12-bit words will be transferred in 64 bytes. The other bits in flags should be set to zero. -... +```julia # open SPI device on channel 1 in mode 3 at 50000 bits per second h = spi_open(pi, 1, 50000, 3) -... +``` """ function spi_open(self::Pi, spi_channel, baud, spi_flags=0) # I p1 spi_channel @@ -98,9 +98,9 @@ Closes the SPI device associated with handle. handle:= >=0 (as returned by a prior call to [*spi_open*]). -... +```julia spi_close(pi, h) -... +``` """ function spi_close(self, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_SPIC, handle, 0)) @@ -117,13 +117,13 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (b, d) = spi_read(pi, h, 60) # read 60 bytes from device h if b == 60 # process read data else # error path -... +``` """ function spi_read(self::Pi, handle, count) # Don't raise exception. Must release lock. @@ -144,7 +144,7 @@ Writes the data bytes to the SPI device associated with handle. handle:= >=0 (as returned by a prior call to [*spi_open*]). data:= the bytes to write. -... +```julia spi_write(pi, 0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 spi_write(pi, 0, b'defgh') # write 5 bytes to device 0 @@ -152,7 +152,7 @@ spi_write(pi, 0, b'defgh') # write 5 bytes to device 0 spi_write(pi, 0, "def") # write 3 bytes to device 0 spi_write(pi, 1, [2, 192, 128]) # write 3 bytes to device 1 -... +``` """ function spi_write(self::Pi, handle, data) # I p1 handle @@ -176,7 +176,7 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (count, rx_data) = spi_xfer(pi, h, b'\\x01\\x80\\x00') (count, rx_data) = spi_xfer(pi, h, [1, 128, 0]) @@ -184,7 +184,7 @@ the error code). (count, rx_data) = spi_xfer(pi, h, b"hello") (count, rx_data) = spi_xfer(pi, h, "hello") -... +``` """ function spi_xfer(self::Pi, handle, data) # I p1 handle @@ -222,11 +222,11 @@ The baud rate must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, or 230400. -... +```julia h1 = serial_open(pi, "/dev/ttyAMA0", 300) h2 = serial_open(pi, "/dev/ttyUSB1", 19200, 0) -... +``` """ function serial_open(self::Pi, tty, baud, ser_flags=0) # I p1 baud @@ -243,9 +243,9 @@ Closes the serial device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). -... +```julia serial_close(pi, h1) -... +``` """ function serial_close(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_SERC, handle, 0)) @@ -256,9 +256,9 @@ Returns a single byte from the device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). -... +```julia b = serial_read_byte(pi, h1) -... +``` """ function serial_read_byte(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_SERRB, handle, 0)) @@ -270,11 +270,11 @@ Writes a single byte to the device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). byte_val:= 0-255, the value to write. -... +```julia serial_write_byte(pi, h1, 23) serial_write_byte(h1, ord(pi, 'Z')) -... +``` """ function serial_write_byte(self::Pi, handle, byte_val) return _u2i( @@ -292,11 +292,11 @@ bytearray containing the bytes. If there was an error the number of bytes read will be less than zero (and will contain the error code). -... +```julia (b, d) = serial_read(pi, h2, 100) if b > 0 # process read data -... +``` """ function serial_read(self::Pi, handle, count) # Don't raise exception. Must release lock. @@ -317,7 +317,7 @@ Writes the data bytes to the device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). data:= the bytes to write. -... +```julia serial_write(pi, h1, b'\\x02\\x03\\x04') serial_write(pi, h2, b'help') @@ -325,7 +325,7 @@ serial_write(pi, h2, b'help') serial_write(pi, h2, "hello") serial_write(pi, h1, [2, 3, 4]) -... +``` """ function serial_write(self::Pi, handle, data) # I p1 handle @@ -344,12 +344,12 @@ device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). -... +```julia rdy = serial_data_available(pi, h1) if rdy > 0 (b, d) = serial_read(pi, h1, rdy) -... +``` """ function serial_data_available(self::Pi, handle) return _u2i(_pigpio_command(self.sl, _PI_CMD_SERDA, handle, 0)) @@ -368,10 +368,10 @@ The serial data is held in a cyclic buffer and is read using It is the caller's responsibility to read data from the cyclic buffer in a timely fashion. -... +```julia status = bb_serial_read_open(pi, 4, 19200) status = bb_serial_read_open(pi, 17, 9600) -... +``` """ function bb_serial_read_open(self, user_gpio, baud, bb_bits=8) # pigpio message format @@ -405,9 +405,9 @@ For [*bb_bits*] 1-8 there will be one byte per character. For [*bb_bits*] 9-16 there will be two bytes per character. For [*bb_bits*] 17-32 there will be four bytes per character. -... +```julia (count, data) = bb_serial_read(pi, 4) -... +``` """ function bb_serial_read(self, user_gpio) # Don't raise exception. Must release lock. @@ -427,9 +427,9 @@ Closes a GPIO for bit bang reading of serial data. user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) -... +```julia status = bb_serial_read_close(pi, 17) -... +``` """ function bb_serial_read_close(self, user_gpio) return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRC, user_gpio, 0)) @@ -441,9 +441,9 @@ Invert serial logic. user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) invert:= 0-1 (1 invert, 0 normal) -... +```julia status = bb_serial_invert(pi, 17, 1) -... +``` """ function bb_serial_invert(self, user_gpio, invert) return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRI, user_gpio, invert)) diff --git a/src/wave.jl b/src/wave.jl index 93a7b51..b313eab 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -2,9 +2,9 @@ Clears all waveforms and any data added by calls to the [*wave_add_**] functions. -... +```julia wave_clear(pi, ) -... +``` """ function wave_clear(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCLR, 0, 0)) @@ -17,9 +17,9 @@ You would not normally need to call this function as it is automatically called after a waveform is created with the [*wave_create*] function. -... +```julia wave_add_new(pi, ) -... +``` """ function wave_add_new(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVNEW, 0, 0)) @@ -42,7 +42,7 @@ If the added waveform is intended to start after or within the existing waveform then the first pulse should consist solely of a delay. -... +```julia G1=4 G2=24 @@ -83,7 +83,7 @@ time.sleep(4) wave_tx_stop(pi, ) # stop waveform wave_clear(pi, ) # clear all waveforms -... +``` """ function wave_add_generic(self::Pi, pulses) # pigpio message format @@ -134,7 +134,7 @@ For [*bb_bits*] 1-8 there will be one byte per character. For [*bb_bits*] 9-16 there will be two bytes per character. For [*bb_bits*] 17-32 there will be four bytes per character. -... +```julia wave_add_serial(pi, 4, 300, 'Hello world') wave_add_serial(pi, 4, 300, b"Hello world") @@ -142,7 +142,7 @@ wave_add_serial(pi, 4, 300, b"Hello world") wave_add_serial(pi, 4, 300, b'\\x23\\x01\\x00\\x45') wave_add_serial(pi, 17, 38400, [23, 128, 234], 5000) -... +``` """ function wave_add_serial( self::Pi, user_gpio, baud, data, offset=0, bb_bits=8, bb_stop=2) @@ -195,9 +195,9 @@ to set all the fields to zero (the pulse will be ignored). When a waveform is started each pulse is executed in order with the specified delay between the pulse and the next. -... +```julia wid = wave_create(pi, ) -... +``` """ function wave_create(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) @@ -210,11 +210,11 @@ wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Wave ids are allocated in order, 0, 1, 2, etc. -... +```julia wave_delete(pi, 6) # delete waveform with id 6 wave_delete(pi, 0) # delete waveform with id 0 -... +``` """ function wave_delete(self::Pi, wave_id) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVDEL, wave_id, 0)) @@ -249,9 +249,9 @@ wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. -... +```julia cbs = wave_send_once(pi, wid) -... +``` """ function wave_send_once(self::Pi, wave_id) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTX, wave_id, 0)) @@ -269,9 +269,9 @@ wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. -... +```julia cbs = wave_send_repeat(pi, wid) -... +``` """ function wave_send_repeat(self::Pi, wave_id) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXR, wave_id, 0)) @@ -304,9 +304,9 @@ wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. -... +```julia cbs = wave_send_using_mode(pi, wid, WAVE_MODE_REPEAT_SYNC) -... +``` """ function wave_send_using_mode(self::Pi, wave_id, mode) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTXM, wave_id, mode)) @@ -322,9 +322,9 @@ values WAVE_NOT_FOUND (9998) - transmitted wave not found. NO_TX_WAVE (9999) - no wave being transmitted. -... +```julia wid = wave_tx_at(pi, ) -... +``` """ function wave_tx_at(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVTAT, 0, 0)) @@ -334,14 +334,14 @@ end Returns 1 if a waveform is currently being transmitted, otherwise 0. -... +```julia wave_send_once(pi, 0) # send first waveform while wave_tx_busy(pi, ): # wait for waveform to be sent time.sleep(0.1) wave_send_once(pi, 1) # send next waveform -... +``` """ function wave_tx_busy(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVBSY, 0, 0)) @@ -353,13 +353,13 @@ Stops the transmission of the current waveform. This function is intended to stop a waveform started with wave_send_repeat. -... +```julia wave_send_repeat(pi, 3) time.sleep(5) wave_tx_stop(pi, ) -... +``` """ function wave_tx_stop(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVHLT, 0, 0)) @@ -402,7 +402,7 @@ If present Loop Forever must be the last entry in the chain. The code is currently dimensioned to support a chain with roughly 600 entries and 20 loop counters. -... +```julia #!/usr/bin/env python import time @@ -449,7 +449,7 @@ for i in range(WAVES) wave_delete(pi, wid[i]) stop(pi, ) -... +``` """ function wave_chain(self::Pi, data) # I p1 0 @@ -464,9 +464,9 @@ end """ Returns the length in microseconds of the current waveform. -... +```julia micros = wave_get_micros(pi, ) -... +``` """ function wave_get_micros(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSM, 0, 0)) @@ -475,9 +475,9 @@ end """ Returns the maximum possible size of a waveform in microseconds. -... +```julia micros = wave_get_max_micros(pi, ) -... +``` """ function wave_get_max_micros(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSM, 2, 0)) @@ -486,9 +486,9 @@ end """ Returns the length in pulses of the current waveform. -... +```julia pulses = wave_get_pulses(pi, ) -... +``` """ function wave_get_pulses(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSP, 0, 0)) @@ -497,9 +497,9 @@ end """ Returns the maximum possible size of a waveform in pulses. -... +```julia pulses = wave_get_max_pulses(pi, ) -... +``` """ function wave_get_max_pulses(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSP, 2, 0)) @@ -509,9 +509,9 @@ end Returns the length in DMA control blocks of the current waveform. -... +```julia cbs = wave_get_cbs(pi, ) -... +``` """ function wave_get_cbs(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSC, 0, 0)) @@ -521,9 +521,9 @@ end Returns the maximum possible size of a waveform in DMA control blocks. -... +```julia cbs = wave_get_max_cbs(pi, ) -... +``` """ function wave_get_max_cbs(self::Pi) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVSC, 2, 0)) From d37395dc3d9c06d568236674dd059f69a7e54883 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:15:07 +0200 Subject: [PATCH 18/51] use backticks for parameters --- src/i2c.jl | 42 +++++++++++++++++----------------- src/wave.jl | 66 ++++++++++++++++++++++++++--------------------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 2953fb4..a104b81 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -5,7 +5,7 @@ i2c_bus:= >=0. i2c_address:= 0-0x7F. i2c_flags:= 0, no flags are currently defined. -Normally you would only use the [*i2c_**] functions if +Normally you would only use the `i2c_*` functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard SMBus module instead. @@ -49,7 +49,7 @@ end """ Closes the I2C device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). ```julia i2c_close(pi, h) @@ -62,7 +62,7 @@ end """ Sends a single bit to the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). bit:= 0 or 1, the value to write. SMBus 2.0 5.5.1 - Quick command. @@ -82,7 +82,7 @@ end """ Sends a single byte to the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). byte_val:= 0-255, the value to write. SMBus 2.0 5.5.2 - Send byte. @@ -103,7 +103,7 @@ end """ Reads a single byte from the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). SMBus 2.0 5.5.3 - Receive byte. ``` @@ -122,7 +122,7 @@ end Writes a single byte to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. byte_val:= 0-255, the value to write. @@ -155,7 +155,7 @@ end Writes a single 16 bit word to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. word_val:= 0-65535, the value to write. @@ -188,7 +188,7 @@ end Reads a single byte from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read byte. @@ -212,7 +212,7 @@ end Reads a single 16 bit word from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read word. @@ -236,7 +236,7 @@ end Writes 16 bits of data to the specified register of the device associated with handle and reads 16 bits of data in return. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. word_val:= 0-65535, the value to write. @@ -267,7 +267,7 @@ end Writes up to 32 bytes to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. data:= the bytes to write. @@ -305,7 +305,7 @@ end Reads a block of up to 32 bytes from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. SMBus 2.0 5.5.7 - Block read. @@ -347,7 +347,7 @@ Writes data bytes to the specified register of the device associated with handle and reads a device specified number of bytes of data in return. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. data:= the bytes to write. @@ -399,7 +399,7 @@ end Writes data bytes to the specified register of the device associated with handle . 1-32 bytes may be written. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. data:= the bytes to write. @@ -435,7 +435,7 @@ end Reads count bytes from the specified register of the device associated with handle . The count may be 1-32. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). reg:= >=0, the device register. count:= >0, the number of bytes to read. @@ -482,7 +482,7 @@ end Returns count bytes read from the raw device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). count:= >0, the number of bytes to read. ``` @@ -514,7 +514,7 @@ end """ Writes the data bytes to the raw device associated with handle. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). data:= the bytes to write. ``` @@ -550,7 +550,7 @@ This function executes a sequence of I2C operations. The operations to be performed are specified by the contents of data which contains the concatenated command codes and associated data. -handle:= >=0 (as returned by a prior call to [*i2c_open*]). +handle:= >=0 (as returned by a prior call to `i2c_open`). data:= the concatenated I2C commands, see below The returned value is a tuple of the number of bytes read and a @@ -658,9 +658,9 @@ end """ This function stops bit banging I2C on a pair of GPIO -previously opened with [*bb_i2c_open*]. +previously opened with `bb_i2c_open`. -SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] +SDA:= 0-31, the SDA GPIO used in a prior call to `bb_i2c_open` Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. @@ -678,7 +678,7 @@ The operations to be performed are specified by the contents of data which contains the concatenated command codes and associated data. -SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) +SDA:= 0-31 (as used in a prior call to `bb_i2c_open`) data:= the concatenated I2C commands, see below The returned value is a tuple of the number of bytes read and a diff --git a/src/wave.jl b/src/wave.jl index b313eab..305bd09 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -1,6 +1,6 @@ """ Clears all waveforms and any data added by calls to the -[*wave_add_**] functions. +`wave_add_*` functions. ```julia wave_clear(pi, ) @@ -15,7 +15,7 @@ Starts a new empty waveform. You would not normally need to call this function as it is automatically called after a waveform is created with the -[*wave_create*] function. +`wave_create` function. ```julia wave_add_new(pi, ) @@ -108,7 +108,7 @@ end """ Adds a waveform representing serial data to the existing -waveform (if any). The serial data starts [*offset*] +waveform (if any). The serial data starts `offset` microseconds from the start of the waveform. user_gpio:= GPIO to transmit data. You must set the GPIO mode @@ -122,17 +122,17 @@ bb_stop:= number of stop half bits, default 2. Returns the new total number of pulses in the current waveform. -The serial data is formatted as one start bit, [*bb_bits*] -data bits, and [*bb_stop*]/2 stop bits. +The serial data is formatted as one start bit, `bb_bits` +data bits, and `bb_stop`/2 stop bits. It is legal to add serial data streams with different baud rates to the same waveform. -The bytes required for each character depend upon [*bb_bits*]. +The bytes required for each character depend upon `bb_bits`. -For [*bb_bits*] 1-8 there will be one byte per character. -For [*bb_bits*] 9-16 there will be two bytes per character. -For [*bb_bits*] 17-32 there will be four bytes per character. +For `bb_bits` 1-8 there will be one byte per character. +For `bb_bits` 9-16 there will be two bytes per character. +For `bb_bits` 17-32 there will be four bytes per character. ```julia wave_add_serial(pi, 4, 300, 'Hello world') @@ -157,29 +157,29 @@ end """ Creates a waveform from the data provided by the prior calls -to the [*wave_add_**] functions. +to the `wave_add_*` functions. Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -The data provided by the [*wave_add_**] functions is consumed by +The data provided by the `wave_add_*` functions is consumed by this function. As many waveforms may be created as there is space available. -The wave id is passed to [*wave_send_**] to specify the waveform +The wave id is passed to `wave_send_*` to specify the waveform to transmit. Normal usage would be -Step 1. [*wave_clear*] to clear all waveforms and added data. +Step 1. `wave_clear` to clear all waveforms and added data. -Step 2. [*wave_add_**] calls to supply the waveform data. +Step 2. `wave_add_*` calls to supply the waveform data. -Step 3. [*wave_create*] to create the waveform and get a unique id +Step 3. `wave_create` to create the waveform and get a unique id Repeat steps 2 and 3 as needed. -Step 4. [*wave_send_**] with the id of the waveform to transmit. +Step 4. `wave_send_*` with the id of the waveform to transmit. A waveform comprises one or more pulses. @@ -206,7 +206,7 @@ end """ This function deletes the waveform with id wave_id. -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +wave_id:= >=0 (as returned by a prior call to `wave_create`). Wave ids are allocated in order, 0, 1, 2, etc. @@ -223,7 +223,7 @@ end """ This function is deprecated and has been removed. -Use [*wave_create*]/[*wave_send_**] instead. +Use `wave_create`/`wave_send_*` instead. """ function wave_tx_start(self::Pi) # DEPRECATED return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0)) @@ -232,7 +232,7 @@ end """ This function is deprecated and has beeen removed. -Use [*wave_create*]/[*wave_send_**] instead. +Use `wave_create`/`wave_send_*` instead. """ function wave_tx_repeat(self::Pi) # DEPRECATED return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0)) @@ -242,10 +242,10 @@ end Transmits the waveform with id wave_id. The waveform is sent once. -NOTE: Any hardware PWM started by [*hardware_PWM*] will +NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +wave_id:= >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. @@ -259,13 +259,13 @@ end """ Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to [*wave_send_**] +until wave_tx_stop is called or another call to `wave_send_*` is made. -NOTE: Any hardware PWM started by [*hardware_PWM*] will +NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +wave_id:= >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. @@ -280,27 +280,27 @@ end """ Transmits the waveform with id wave_id using mode mode. -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +wave_id:= >=0 (as returned by a prior call to `wave_create`). mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. -WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. +WAVE_MODE_ONE_SHOT: same as `wave_send_once`. -WAVE_MODE_REPEAT same as [*wave_send_repeat*]. +WAVE_MODE_REPEAT same as `wave_send_repeat`. -WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries +WAVE_MODE_ONE_SHOT_SYNC same as `wave_send_once` but tries to sync with the previous waveform. -WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries +WAVE_MODE_REPEAT_SYNC same as `wave_send_repeat` but tries to sync with the previous waveform. WARNING: bad things may happen if you delete the previous waveform before it has been synced to the new waveform. -NOTE: Any hardware PWM started by [*hardware_PWM*] will +NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to [*wave_create*]). +wave_id:= >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. @@ -368,11 +368,11 @@ end """ This function transmits a chain of waveforms. -NOTE: Any hardware PWM started by [*hardware_PWM*] +NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. The waves to be transmitted are specified by the contents -of data which contains an ordered list of [*wave_id*]s +of data which contains an ordered list of `wave_id`s and optional command codes and related data. Returns 0 if OK, otherwise PI_CHAIN_NESTING, From 8cb1b96c3ce458bd4c17b4a8a78d74bfc32d955d Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:16:46 +0200 Subject: [PATCH 19/51] use backticks for parameters in spiSerial.jl --- src/spiSerial.jl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index b351b58..8b92a68 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -13,7 +13,7 @@ spi_channel:= 0-1 (0-2 for the auxiliary SPI device). baud:= 32K-125M (values above 30M are unlikely to work). spi_flags:= see below. -Normally you would only use the [*spi_**] functions if +Normally you would only use the `spi_*` functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard SPI module instead. @@ -63,7 +63,7 @@ first. Auxiliary SPI device only. bbbbbb defines the word size in bits (0-32). The default (0) sets 8 bits per word. Auxiliary SPI device only. -The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions +The `spi_read`, `spi_write`, and `spi_xfer` functions transfer data packed into 1, 2, or 4 bytes according to the word size in bits. @@ -96,7 +96,7 @@ end """ Closes the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to [*spi_open*]). +handle:= >=0 (as returned by a prior call to `spi_open`). ```julia spi_close(pi, h) @@ -109,7 +109,7 @@ end """ Reads count bytes from the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to [*spi_open*]). +handle:= >=0 (as returned by a prior call to `spi_open`). count:= >0, the number of bytes to read. The returned value is a tuple of the number of bytes read and a @@ -141,7 +141,7 @@ end """ Writes the data bytes to the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to [*spi_open*]). +handle:= >=0 (as returned by a prior call to `spi_open`). data:= the bytes to write. ```julia @@ -168,7 +168,7 @@ end Writes the data bytes to the SPI device associated with handle, returning the data bytes read from the device. -handle:= >=0 (as returned by a prior call to [*spi_open*]). +handle:= >=0 (as returned by a prior call to `spi_open`). data:= the bytes to write. The returned value is a tuple of the number of bytes read and a @@ -213,7 +213,7 @@ tty:= the serial device to open. baud:= baud rate in bits per second, see below. ser_flags:= 0, no flags are currently defined. -Normally you would only use the [*serial_**] functions if +Normally you would only use the `serial_*` functions if you are or will be connecting to the Pi over a network. If you will always run on the local Pi use the standard serial module instead. @@ -241,7 +241,7 @@ end """ Closes the serial device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). ```julia serial_close(pi, h1) @@ -254,7 +254,7 @@ end """ Returns a single byte from the device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). ```julia b = serial_read_byte(pi, h1) @@ -267,7 +267,7 @@ end """ Writes a single byte to the device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). byte_val:= 0-255, the value to write. ```julia @@ -284,7 +284,7 @@ end """ Reads up to count bytes from the device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). count:= >0, the number of bytes to read. The returned value is a tuple of the number of bytes read and a @@ -314,7 +314,7 @@ end """ Writes the data bytes to the device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). data:= the bytes to write. ```julia @@ -342,7 +342,7 @@ end Returns the number of bytes available to be read from the device associated with handle. -handle:= >=0 (as returned by a prior call to [*serial_open*]). +handle:= >=0 (as returned by a prior call to `serial_open`). ```julia rdy = serial_data_available(pi, h1) @@ -363,7 +363,7 @@ baud:= 50-250000, the baud rate. bb_bits:= 1-32, the number of bits per word, default 8. The serial data is held in a cyclic buffer and is read using -[*bb_serial_read*]. +`bb_serial_read`. It is the caller's responsibility to read data from the cyclic buffer in a timely fashion. @@ -390,7 +390,7 @@ end """ Returns data from the bit bang serial cyclic buffer. -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) +user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -398,12 +398,12 @@ number of bytes read will be less than zero (and will contain the error code). The bytes returned for each character depend upon the number of -data bits [*bb_bits*] specified in the [*bb_serial_read_open*] +data bits `bb_bits` specified in the `bb_serial_read_open` command. -For [*bb_bits*] 1-8 there will be one byte per character. -For [*bb_bits*] 9-16 there will be two bytes per character. -For [*bb_bits*] 17-32 there will be four bytes per character. +For `bb_bits` 1-8 there will be one byte per character. +For `bb_bits` 9-16 there will be two bytes per character. +For `bb_bits` 17-32 there will be four bytes per character. ```julia (count, data) = bb_serial_read(pi, 4) @@ -425,7 +425,7 @@ end """ Closes a GPIO for bit bang reading of serial data. -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) +user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) ```julia status = bb_serial_read_close(pi, 17) @@ -438,7 +438,7 @@ end """ Invert serial logic. -user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) +user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) invert:= 0-1 (1 invert, 0 normal) ```julia From c2ffdeebeba4b38bcbe0c46fd10017e0d62961fe Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 19:43:54 +0200 Subject: [PATCH 20/51] use backticks for parameters --- src/i2c.jl | 9 ++++++--- src/pi.jl | 34 +++++++++++++++++----------------- src/spiSerial.jl | 22 +++++++++++----------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index a104b81..7887351 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -632,8 +632,8 @@ SDA:= 0-31 SCL:= 0-31 baud:= 50-500000 -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. +Returns 0 if OK, otherwise `PiGPIO.PI_BAD_USER_GPIO`, `PiGPIO.PI_BAD_I2C_BAUD`, +or `PiGPIO.PI_GPIO_IN_USE`. NOTE @@ -662,7 +662,8 @@ previously opened with `bb_i2c_open`. SDA:= 0-31, the SDA GPIO used in a prior call to `bb_i2c_open` -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +Returns 0 if OK, otherwise `PiGPIO.PI_BAD_USER_GPIO`, or +`PiGPIO.PI_NOT_I2C_GPIO`. ```julia bb_i2c_close(pi, SDA) @@ -693,6 +694,7 @@ the error code). The following command codes are supported +``` Name @ Cmd & Data @ Meaning End @ 0 @ No more commands Escape @ 1 @ Next P is two bytes @@ -702,6 +704,7 @@ Address @ 4 P @ Set I2C address to P Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) Read @ 6 P @ Read P bytes of data Write @ 7 P ... @ Write P bytes of data +``` The address, read, and write commands take a parameter P. Normally P is one byte (0-255). If the command is preceded by diff --git a/src/pi.jl b/src/pi.jl index 782d657..60de99c 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -96,10 +96,10 @@ end """ Runs a pigpio socket command. -sl:= command socket and lock. -cmd:= the command to be executed. -p1:= command parameter 1 (if applicable). - p2:= command parameter 2 (if applicable). +* `sl`: command socket and lock. +* `cmd`: the command to be executed. +* `p1`: command parameter 1 (if applicable). +* `p2`: command parameter 2 (if applicable). """ function _pigpio_command(sl::SockLock, cmd::Integer, p1::Integer, p2::Integer, rl=true) lock(sl.l) @@ -634,7 +634,7 @@ end """ Returns the frequency of PWM being used on the GPIO. -user_gpio:= 0-31. +`user_gpio`= 0-31. Returns the frequency (in Hz) used for the GPIO. @@ -664,8 +664,8 @@ end """ Starts (500-2500) or stops (0) servo pulses on the GPIO. -user_gpio:= 0-31. -pulsewidth:= 0 (off), +`user_gpio`:= 0-31. +`pulsewidth`:= 0 (off), 500 (most anti-clockwise) - 2500 (most clockwise). The selected pulsewidth will continue to be transmitted until @@ -693,7 +693,7 @@ end """ Returns the servo pulsewidth being used on the GPIO. -user_gpio:= 0-31. +`user_gpio`:= 0-31. Returns the servo pulsewidth. @@ -831,8 +831,8 @@ end """ Sets a watchdog timeout for a GPIO. - user_gpio:= 0-31. -wdog_timeout:= 0-60000. +* `user_gpio`: 0-31. +* `wdog_timeout`: 0-60000. The watchdog is nominally in milliseconds. @@ -1224,9 +1224,9 @@ end Calls a user supplied function (a callback) whenever the specified GPIO edge is detected. -user_gpio:= 0-31. -edge:= `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE` (default), or `PiGPIO.FALLING_EDGE`. -func:= user supplied callback function. +* `user_gpio`: 0-31. +* `edge`: `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE` (default), or `PiGPIO.FALLING_EDGE`. +* `func`: user supplied callback function. The user supplied callback receives three parameters, the GPIO, the level, and the tick. @@ -1266,10 +1266,10 @@ end """ Wait for an edge event on a GPIO. -user_gpio:= 0-31. - edge:= EITHER_EDGE, RISING_EDGE (default), or - FALLING_EDGE. -wait_timeout:= >=0.0 (default 60.0). +* `user_gpio`: 0-31. +* `edge`: `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE` (default), or + `PiGPIO.FALLING_EDGE`. +* `wait_timeout`: >=0.0 (default 60.0). The function returns when the edge is detected or after the number of seconds specified by timeout has expired. diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 8b92a68..1d60263 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -9,9 +9,9 @@ A and B and may be selected by setting the A bit in the flags. The auxiliary device has 3 chip selects and a selectable word size in bits. -spi_channel:= 0-1 (0-2 for the auxiliary SPI device). - baud:= 32K-125M (values above 30M are unlikely to work). -spi_flags:= see below. +`spi_channel`:= 0-1 (0-2 for the auxiliary SPI device). +`baud`:= 32K-125M (values above 30M are unlikely to work). +`spi_flags`:= see below. Normally you would only use the `spi_*` functions if you are or will be connecting to the Pi over a network. If @@ -342,7 +342,7 @@ end Returns the number of bytes available to be read from the device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). +`handle`:= >=0 (as returned by a prior call to `serial_open`). ```julia rdy = serial_data_available(pi, h1) @@ -358,9 +358,9 @@ end """ Opens a GPIO for bit bang reading of serial data. -user_gpio:= 0-31, the GPIO to use. -baud:= 50-250000, the baud rate. -bb_bits:= 1-32, the number of bits per word, default 8. +`user_gpio`:= 0-31, the GPIO to use. +`baud`:= 50-250000, the baud rate. +`bb_bits`:= 1-32, the number of bits per word, default 8. The serial data is held in a cyclic buffer and is read using `bb_serial_read`. @@ -390,7 +390,7 @@ end """ Returns data from the bit bang serial cyclic buffer. -user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) +`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -425,7 +425,7 @@ end """ Closes a GPIO for bit bang reading of serial data. -user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) +`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) ```julia status = bb_serial_read_close(pi, 17) @@ -438,8 +438,8 @@ end """ Invert serial logic. -user_gpio:= 0-31 (opened in a prior call to `bb_serial_read_open`) -invert:= 0-1 (1 invert, 0 normal) +`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) +`invert`:= 0-1 (1 invert, 0 normal) ```julia status = bb_serial_invert(pi, 17, 1) From 9c6626aa56b87f9028e05487087fb79164103a74 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 20:09:35 +0200 Subject: [PATCH 21/51] use markdown list for parameters --- docs/make.jl | 4 +- src/i2c.jl | 96 ++++++++++++++++++++++++------------------------ src/pi.jl | 47 ++++++++++++------------ src/spiSerial.jl | 58 ++++++++++++++--------------- src/wave.jl | 26 ++++++------- 5 files changed, 115 insertions(+), 116 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 44cc43b..5cf55da 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -11,8 +11,8 @@ makedocs( format = Documenter.HTML(), modules = [PiGPIO], # examples need to be run on a Raspberry Pi - # doctest = false, - # draft = true, + doctest = false, + draft = true, pages = [ "index.md", "Tutorial" => "tutorial.md", diff --git a/src/i2c.jl b/src/i2c.jl index 7887351..4718570 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -1,9 +1,9 @@ """ Returns a handle (>=0) for the device at the I2C bus address. -i2c_bus:= >=0. -i2c_address:= 0-0x7F. -i2c_flags:= 0, no flags are currently defined. + * `i2c_bus`: >=0. + * `i2c_address`: 0-0x7F. + * `i2c_flags`: 0, no flags are currently defined. Normally you would only use the `i2c_*` functions if you are or will be connecting to the Pi over a network. If @@ -49,7 +49,7 @@ end """ Closes the I2C device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). + * `handle`: >=0 (as returned by a prior call to `i2c_open`). ```julia i2c_close(pi, h) @@ -62,8 +62,8 @@ end """ Sends a single bit to the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -bit:= 0 or 1, the value to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `bit`: 0 or 1, the value to write. SMBus 2.0 5.5.1 - Quick command. ``` @@ -82,8 +82,8 @@ end """ Sends a single byte to the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -byte_val:= 0-255, the value to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `byte_val`: 0-255, the value to write. SMBus 2.0 5.5.2 - Send byte. ``` @@ -103,7 +103,7 @@ end """ Reads a single byte from the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). + * `handle`: >=0 (as returned by a prior call to `i2c_open`). SMBus 2.0 5.5.3 - Receive byte. ``` @@ -122,9 +122,9 @@ end Writes a single byte to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -byte_val:= 0-255, the value to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `byte_val`: 0-255, the value to write. SMBus 2.0 5.5.4 - Write byte. ``` @@ -155,9 +155,9 @@ end Writes a single 16 bit word to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -word_val:= 0-65535, the value to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `word_val`: 0-65535, the value to write. SMBus 2.0 5.5.4 - Write word. ``` @@ -188,8 +188,8 @@ end Reads a single byte from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. SMBus 2.0 5.5.5 - Read byte. ``` @@ -212,8 +212,8 @@ end Reads a single 16 bit word from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. SMBus 2.0 5.5.5 - Read word. ``` @@ -236,9 +236,9 @@ end Writes 16 bits of data to the specified register of the device associated with handle and reads 16 bits of data in return. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -word_val:= 0-65535, the value to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `word_val`: 0-65535, the value to write. SMBus 2.0 5.5.6 - Process call. ``` @@ -267,9 +267,9 @@ end Writes up to 32 bytes to the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `data`: the bytes to write. SMBus 2.0 5.5.7 - Block write. ``` @@ -305,8 +305,8 @@ end Reads a block of up to 32 bytes from the specified register of the device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. SMBus 2.0 5.5.7 - Block read. ``` @@ -347,9 +347,9 @@ Writes data bytes to the specified register of the device associated with handle and reads a device specified number of bytes of data in return. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `data`: the bytes to write. The SMBus 2.0 documentation states that a minimum of 1 byte may be sent and a minimum of 1 byte may be received. The total @@ -399,9 +399,9 @@ end Writes data bytes to the specified register of the device associated with handle . 1-32 bytes may be written. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `data`: the bytes to write. ``` S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P @@ -435,9 +435,9 @@ end Reads count bytes from the specified register of the device associated with handle . The count may be 1-32. -handle:= >=0 (as returned by a prior call to `i2c_open`). -reg:= >=0, the device register. -count:= >0, the number of bytes to read. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `reg`: >=0, the device register. + * `count`: >0, the number of bytes to read. ``` S Addr Wr [A] reg [A] @@ -482,8 +482,8 @@ end Returns count bytes read from the raw device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -count:= >0, the number of bytes to read. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `count`: >0, the number of bytes to read. ``` S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P @@ -514,8 +514,8 @@ end """ Writes the data bytes to the raw device associated with handle. -handle:= >=0 (as returned by a prior call to `i2c_open`). -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `data`: the bytes to write. ``` S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P @@ -550,8 +550,8 @@ This function executes a sequence of I2C operations. The operations to be performed are specified by the contents of data which contains the concatenated command codes and associated data. -handle:= >=0 (as returned by a prior call to `i2c_open`). -data:= the concatenated I2C commands, see below + * `handle`: >=0 (as returned by a prior call to `i2c_open`). + * `data`: the concatenated I2C commands, see below The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -628,9 +628,9 @@ o repeated starts o clock stretching o I2C on any pair of spare GPIO -SDA:= 0-31 -SCL:= 0-31 -baud:= 50-500000 + * `SDA`: 0-31 + * `SCL`: 0-31 + * `baud`: 50-500000 Returns 0 if OK, otherwise `PiGPIO.PI_BAD_USER_GPIO`, `PiGPIO.PI_BAD_I2C_BAUD`, or `PiGPIO.PI_GPIO_IN_USE`. @@ -660,7 +660,7 @@ end This function stops bit banging I2C on a pair of GPIO previously opened with `bb_i2c_open`. -SDA:= 0-31, the SDA GPIO used in a prior call to `bb_i2c_open` + * `SDA`: 0-31, the SDA GPIO used in a prior call to `bb_i2c_open` Returns 0 if OK, otherwise `PiGPIO.PI_BAD_USER_GPIO`, or `PiGPIO.PI_NOT_I2C_GPIO`. @@ -679,8 +679,8 @@ The operations to be performed are specified by the contents of data which contains the concatenated command codes and associated data. -SDA:= 0-31 (as used in a prior call to `bb_i2c_open`) -data:= the concatenated I2C commands, see below + * `SDA`: 0-31 (as used in a prior call to `bb_i2c_open`) + * `data`: the concatenated I2C commands, see below The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the diff --git a/src/pi.jl b/src/pi.jl index 60de99c..3ed9796 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -115,12 +115,12 @@ end """ Runs an extended pigpio socket command. - sl:= command socket and lock. - cmd:= the command to be executed. - p1:= command parameter 1 (if applicable). - p2:= command parameter 2 (if applicable). - p3:= total size in bytes of following extents -extents:= additional data blocks + * `sl`: command socket and lock. + * `cmd`: the command to be executed. + * `p1`: command parameter 1 (if applicable). + * `p2`: command parameter 2 (if applicable). + * `p3`: total size in bytes of following extents + * `extents`: additional data blocks """ function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=true) ext = IOBuffer() @@ -139,9 +139,9 @@ end """An ADT class to hold callback information - gpio:= Broadcom GPIO number. - edge:= `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE`, or `PiGPIO.FALLING_EDGE`. - func:= a user function taking three arguments (GPIO, level, tick). + * `gpio`: Broadcom GPIO number. + * `edge`: `PiGPIO.EITHER_EDGE`, `PiGPIO.RISING_EDGE`, or `PiGPIO.FALLING_EDGE`. + * `func`: a user function taking three arguments (GPIO, level, tick). """ mutable struct Callback_ADT gpio::Int @@ -465,8 +465,8 @@ end Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. -user_gpio:= 0-31. -dutycycle:= 0-range (range defaults to 255). + * `user_gpio`: 0-31. + * `dutycycle`: 0-range (range defaults to 255). The `set_PWM_range` function can change the default range of 255. @@ -487,7 +487,7 @@ end PiGPIO.get_PWM_dutycycle(self::Pi, user_gpio) Returns the PWM dutycycle being used on the GPIO. -user_gpio:= 0-31. + * `user_gpio`: 0-31. For normal PWM the dutycycle will be out of the defined range for the GPIO (see `get_PWM_range`). @@ -553,7 +553,7 @@ end Returns the real (underlying) range of PWM values being used on the GPIO. -user_gpio:= 0-31. + * `user_gpio`: 0-31. If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). @@ -574,8 +574,8 @@ end """ Sets the frequency (in Hz) of the PWM to be used on the GPIO. -user_gpio:= 0-31. -frequency:= >=0 Hz + * `user_gpio`: 0-31. + * `frequency`: >=0 Hz Returns the numerically closest frequency if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PERMITTED. @@ -664,9 +664,8 @@ end """ Starts (500-2500) or stops (0) servo pulses on the GPIO. -`user_gpio`:= 0-31. -`pulsewidth`:= 0 (off), - 500 (most anti-clockwise) - 2500 (most clockwise). +* `user_gpio`: 0-31. +* `pulsewidth`: 0 (off), 500 (most anti-clockwise) - 2500 (most clockwise). The selected pulsewidth will continue to be transmitted until changed by a subsequent call to set_servo_pulsewidth. @@ -693,7 +692,7 @@ end """ Returns the servo pulsewidth being used on the GPIO. -`user_gpio`:= 0-31. +* `user_gpio`: 0-31. Returns the servo pulsewidth. @@ -768,8 +767,8 @@ end """ Starts notifications on a handle. -handle:= >=0 (as returned by a prior call to `notify_open`) -bits:= a 32 bit mask indicating the GPIO to be notified. + * `handle`: >=0 (as returned by a prior call to `notify_open`) + * `bits`: a 32 bit mask indicating the GPIO to be notified. The notification sends state changes for each GPIO whose corresponding bit in bits is set. @@ -790,7 +789,7 @@ end """ Pauses notifications on a handle. -handle:= >=0 (as returned by a prior call to `notify_open`) + * `handle`: >=0 (as returned by a prior call to `notify_open`) Notifications for the handle are suspended until `notify_begin` is called again. @@ -813,7 +812,7 @@ end """ Stops notifications on a handle and releases the handle for reuse. -handle:= >=0 (as returned by a prior call to `notify_open`) + * `handle`: >=0 (as returned by a prior call to `notify_open`) ```julia h = notify_open(pi) @@ -947,7 +946,7 @@ end """ Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -bits:= a 32 bit mask with 1 set if the corresponding GPIO is + * `bits`: a 32 bit mask with 1 set if the corresponding GPIO is to be set. A returned status of `PiGPIO.PI_SOME_PERMITTED` indicates that the user diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 1d60263..ad4d6fb 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -9,9 +9,9 @@ A and B and may be selected by setting the A bit in the flags. The auxiliary device has 3 chip selects and a selectable word size in bits. -`spi_channel`:= 0-1 (0-2 for the auxiliary SPI device). -`baud`:= 32K-125M (values above 30M are unlikely to work). -`spi_flags`:= see below. +* `spi_channel`: 0-1 (0-2 for the auxiliary SPI device). +* `baud`: 32K-125M (values above 30M are unlikely to work). +* `spi_flags`: see below. Normally you would only use the `spi_*` functions if you are or will be connecting to the Pi over a network. If @@ -96,7 +96,7 @@ end """ Closes the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to `spi_open`). + * `handle`: >=0 (as returned by a prior call to `spi_open`). ```julia spi_close(pi, h) @@ -109,8 +109,8 @@ end """ Reads count bytes from the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to `spi_open`). -count:= >0, the number of bytes to read. + * `handle`: >=0 (as returned by a prior call to `spi_open`). + * `count`: >0, the number of bytes to read. The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -141,8 +141,8 @@ end """ Writes the data bytes to the SPI device associated with handle. -handle:= >=0 (as returned by a prior call to `spi_open`). -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `spi_open`). + * `data`: the bytes to write. ```julia spi_write(pi, 0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 @@ -168,8 +168,8 @@ end Writes the data bytes to the SPI device associated with handle, returning the data bytes read from the device. -handle:= >=0 (as returned by a prior call to `spi_open`). -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `spi_open`). + * `data`: the bytes to write. The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -209,9 +209,9 @@ end Returns a handle for the serial tty device opened at baud bits per second. -tty:= the serial device to open. -baud:= baud rate in bits per second, see below. -ser_flags:= 0, no flags are currently defined. + * `tty`: the serial device to open. + * `baud`: baud rate in bits per second, see below. + * `ser_flags`: 0, no flags are currently defined. Normally you would only use the `serial_*` functions if you are or will be connecting to the Pi over a network. If @@ -241,7 +241,7 @@ end """ Closes the serial device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). + * `handle`: >=0 (as returned by a prior call to `serial_open`). ```julia serial_close(pi, h1) @@ -254,7 +254,7 @@ end """ Returns a single byte from the device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). + * `handle`: >=0 (as returned by a prior call to `serial_open`). ```julia b = serial_read_byte(pi, h1) @@ -267,8 +267,8 @@ end """ Writes a single byte to the device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). -byte_val:= 0-255, the value to write. + * `handle`: >=0 (as returned by a prior call to `serial_open`). + * `byte_val`: 0-255, the value to write. ```julia serial_write_byte(pi, h1, 23) @@ -284,8 +284,8 @@ end """ Reads up to count bytes from the device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). -count:= >0, the number of bytes to read. + * `handle`: >=0 (as returned by a prior call to `serial_open`). + * `count`: >0, the number of bytes to read. The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -314,8 +314,8 @@ end """ Writes the data bytes to the device associated with handle. -handle:= >=0 (as returned by a prior call to `serial_open`). -data:= the bytes to write. + * `handle`: >=0 (as returned by a prior call to `serial_open`). + * `data`: the bytes to write. ```julia serial_write(pi, h1, b'\\x02\\x03\\x04') @@ -342,7 +342,7 @@ end Returns the number of bytes available to be read from the device associated with handle. -`handle`:= >=0 (as returned by a prior call to `serial_open`). +* `handle`: >=0 (as returned by a prior call to `serial_open`). ```julia rdy = serial_data_available(pi, h1) @@ -358,9 +358,9 @@ end """ Opens a GPIO for bit bang reading of serial data. -`user_gpio`:= 0-31, the GPIO to use. -`baud`:= 50-250000, the baud rate. -`bb_bits`:= 1-32, the number of bits per word, default 8. +* `user_gpio`: 0-31, the GPIO to use. +* `baud`: 50-250000, the baud rate. +* `bb_bits`: 1-32, the number of bits per word, default 8. The serial data is held in a cyclic buffer and is read using `bb_serial_read`. @@ -390,7 +390,7 @@ end """ Returns data from the bit bang serial cyclic buffer. -`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) +* `user_gpio`: 0-31 (opened in a prior call to `bb_serial_read_open`) The returned value is a tuple of the number of bytes read and a bytearray containing the bytes. If there was an error the @@ -425,7 +425,7 @@ end """ Closes a GPIO for bit bang reading of serial data. -`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) +* `user_gpio`: 0-31 (opened in a prior call to `bb_serial_read_open`) ```julia status = bb_serial_read_close(pi, 17) @@ -438,8 +438,8 @@ end """ Invert serial logic. -`user_gpio`:= 0-31 (opened in a prior call to `bb_serial_read_open`) -`invert`:= 0-1 (1 invert, 0 normal) +* `user_gpio`: 0-31 (opened in a prior call to `bb_serial_read_open`) +* `invert`: 0-1 (1 invert, 0 normal) ```julia status = bb_serial_invert(pi, 17, 1) diff --git a/src/wave.jl b/src/wave.jl index 305bd09..4a7e1d3 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -28,7 +28,7 @@ end """ Adds a list of pulses to the current waveform. -pulses:= list of pulses to add to the waveform. + * `pulses`: list of pulses to add to the waveform. Returns the new total number of pulses in the current waveform. @@ -111,14 +111,14 @@ Adds a waveform representing serial data to the existing waveform (if any). The serial data starts `offset` microseconds from the start of the waveform. -user_gpio:= GPIO to transmit data. You must set the GPIO mode + * `user_gpio`: GPIO to transmit data. You must set the GPIO mode to output. -baud:= 50-1000000 bits per second. -data:= the bytes to write. -offset:= number of microseconds from the start of the + * `baud`: 50-1000000 bits per second. + * `data`: the bytes to write. + * `offset`: number of microseconds from the start of the waveform, default 0. -bb_bits:= number of data bits, default 8. -bb_stop:= number of stop half bits, default 2. + * `bb_bits`: number of data bits, default 8. + * `bb_stop`: number of stop half bits, default 2. Returns the new total number of pulses in the current waveform. @@ -206,7 +206,7 @@ end """ This function deletes the waveform with id wave_id. -wave_id:= >=0 (as returned by a prior call to `wave_create`). + * `wave_id`: >=0 (as returned by a prior call to `wave_create`). Wave ids are allocated in order, 0, 1, 2, etc. @@ -245,7 +245,7 @@ once. NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to `wave_create`). + * `wave_id`: >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. @@ -265,7 +265,7 @@ is made. NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to `wave_create`). + * `wave_id`: >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. @@ -280,8 +280,8 @@ end """ Transmits the waveform with id wave_id using mode mode. -wave_id:= >=0 (as returned by a prior call to `wave_create`). -mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, + * `wave_id`: >=0 (as returned by a prior call to `wave_create`). + * `mode`: WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. WAVE_MODE_ONE_SHOT: same as `wave_send_once`. @@ -300,7 +300,7 @@ waveform before it has been synced to the new waveform. NOTE: Any hardware PWM started by `hardware_PWM` will be cancelled. -wave_id:= >=0 (as returned by a prior call to `wave_create`). + * `wave_id`: >=0 (as returned by a prior call to `wave_create`). Returns the number of DMA control blocks used in the waveform. From c2d069ea2e58235be56adb07f9a0065c75c21c04 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 20:15:15 +0200 Subject: [PATCH 22/51] improve markdown formatting --- src/wave.jl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/wave.jl b/src/wave.jl index 4a7e1d3..570dce3 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -280,18 +280,18 @@ end """ Transmits the waveform with id wave_id using mode mode. - * `wave_id`: >=0 (as returned by a prior call to `wave_create`). - * `mode`: WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, - WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. + * `wave_id`: >0= (as returned by a prior call to `wave_create`). + * `mode`: `PiGPIO.WAVE_MODE_ONE_SHOT`, `PiGPIO.WAVE_MODE_REPEAT`, + `PiGPIO.WAVE_MODE_ONE_SHOT_SYNC`, or `PiGPIO.WAVE_MODE_REPEAT_SYNC`. -WAVE_MODE_ONE_SHOT: same as `wave_send_once`. +`PiGPIO.WAVE_MODE_ONE_SHOT`: same as `wave_send_once`. -WAVE_MODE_REPEAT same as `wave_send_repeat`. +`PiGPIO.WAVE_MODE_REPEAT` same as `wave_send_repeat`. -WAVE_MODE_ONE_SHOT_SYNC same as `wave_send_once` but tries +`PiGPIO.WAVE_MODE_ONE_SHOT_SYNC` same as `wave_send_once` but tries to sync with the previous waveform. -WAVE_MODE_REPEAT_SYNC same as `wave_send_repeat` but tries +`PiGPIO.WAVE_MODE_REPEAT_SYNC` same as `wave_send_repeat` but tries to sync with the previous waveform. WARNING: bad things may happen if you delete the previous @@ -305,7 +305,7 @@ be cancelled. Returns the number of DMA control blocks used in the waveform. ```julia -cbs = wave_send_using_mode(pi, wid, WAVE_MODE_REPEAT_SYNC) +cbs = wave_send_using_mode(pi, wid, PiGPIO.WAVE_MODE_REPEAT_SYNC) ``` """ function wave_send_using_mode(self::Pi, wave_id, mode) @@ -319,8 +319,8 @@ transmitted. Returns the waveform id or one of the following special values -WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. +`PiGPIO.WAVE_NOT_FOUND` (9998) - transmitted wave not found. +`PiGPIO.NO_TX_WAVE` (9999) - no wave being transmitted. ```julia wid = wave_tx_at(pi, ) @@ -351,14 +351,14 @@ end Stops the transmission of the current waveform. This function is intended to stop a waveform started with -wave_send_repeat. +`wave_send_repeat`. ```julia wave_send_repeat(pi, 3) -time.sleep(5) +sleep(5) -wave_tx_stop(pi, ) +wave_tx_stop(pi) ``` """ function wave_tx_stop(self::Pi) @@ -391,11 +391,13 @@ Delays between waves may be added with the delay command. The following command codes are supported +``` Name @ Cmd & Data @ Meaning Loop Start @ 255 0 @ Identify start of a wave block Loop Repeat @ 255 1 x y @ loop x + y*256 times Delay @ 255 2 x y @ delay x + y*256 microseconds Loop Forever @ 255 3 @ loop forever +``` If present Loop Forever must be the last entry in the chain. From 2eaa9435c9ea5d66c3bb40b38074b68dc7c8cf75 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 9 Sep 2024 20:28:45 +0200 Subject: [PATCH 23/51] use admonitions --- src/i2c.jl | 6 +++--- src/pi.jl | 5 +++-- src/spiSerial.jl | 5 +++-- src/wave.jl | 29 +++++++++++++++++------------ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 4718570..4787981 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -635,10 +635,10 @@ o I2C on any pair of spare GPIO Returns 0 if OK, otherwise `PiGPIO.PI_BAD_USER_GPIO`, `PiGPIO.PI_BAD_I2C_BAUD`, or `PiGPIO.PI_GPIO_IN_USE`. -NOTE +!!! note -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. + As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. ```julia h = bb_i2c_open(pi, 4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps diff --git a/src/pi.jl b/src/pi.jl index 3ed9796..e04a7c8 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -1010,8 +1010,9 @@ end Starts hardware PWM on a GPIO at the specified frequency and dutycycle. Frequencies above 30MHz are unlikely to work. -NOTE: Any waveform started by `wave_send_once`, -`wave_send_repeat`, or `wave_chain` will be cancelled. +!!! note + Any waveform started by `wave_send_once`, `wave_send_repeat`, or + `wave_chain` will be cancelled. This function is only valid if the pigpio main clock is PCM. The main clock defaults to PCM but may be overridden when the diff --git a/src/spiSerial.jl b/src/spiSerial.jl index ad4d6fb..97ee12d 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -27,8 +27,9 @@ b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m mm defines the SPI mode. -WARNING: modes 1 and 3 do not appear to work on -the auxiliary device. +!!! warning + + modes 1 and 3 do not appear to work on the auxiliary device. . . Mode POL PHA diff --git a/src/wave.jl b/src/wave.jl index 570dce3..e291903 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -242,8 +242,9 @@ end Transmits the waveform with id wave_id. The waveform is sent once. -NOTE: Any hardware PWM started by `hardware_PWM` will -be cancelled. +!!! note + + Any hardware PWM started by `hardware_PWM` will be cancelled. * `wave_id`: >=0 (as returned by a prior call to `wave_create`). @@ -258,12 +259,14 @@ function wave_send_once(self::Pi, wave_id) end """ -Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to `wave_send_*` + PiGPIO.wave_send_repeat(self::Pi, wave_id) + +Transmits the waveform with id `wave_id`. The waveform repeats +until `wave_tx_stop` is called or another call to `wave_send_*` is made. -NOTE: Any hardware PWM started by `hardware_PWM` will -be cancelled. +!!! note + Any hardware PWM started by `hardware_PWM` will be cancelled. * `wave_id`: >=0 (as returned by a prior call to `wave_create`). @@ -294,11 +297,13 @@ to sync with the previous waveform. `PiGPIO.WAVE_MODE_REPEAT_SYNC` same as `wave_send_repeat` but tries to sync with the previous waveform. -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. +!!! warning + + Bad things may happen if you delete the previous waveform before it has been synced to the new waveform. + +!!! note -NOTE: Any hardware PWM started by `hardware_PWM` will -be cancelled. + Any hardware PWM started by `hardware_PWM` will be cancelled. * `wave_id`: >=0 (as returned by a prior call to `wave_create`). @@ -368,8 +373,8 @@ end """ This function transmits a chain of waveforms. -NOTE: Any hardware PWM started by `hardware_PWM` -will be cancelled. +!!! note + Any hardware PWM started by `hardware_PWM` will be cancelled. The waves to be transmitted are specified by the contents of data which contains an ordered list of `wave_id`s From 74f21545006cbdb1fe7371ddbe63fab40cd9cb44 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Tue, 10 Sep 2024 00:56:02 -0400 Subject: [PATCH 24/51] Update TagBot.yml --- .github/workflows/TagBot.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index 0bc129d..4bad0ec 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -1,11 +1,33 @@ name: TagBot on: - schedule: - - cron: 10 20 * * * + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: "3" +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read jobs: TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' runs-on: ubuntu-latest steps: - uses: JuliaRegistries/TagBot@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + # Edit the following line to reflect the actual name of the GitHub Secret containing your private key + ssh: ${{ secrets.DOCUMENTER_KEY }} + # ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }} From c71f6943c12fd405ee06eb12fa77a00a6b1a329b Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 23 Sep 2024 18:46:16 +0200 Subject: [PATCH 25/51] specify namespace of unexported constants --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3a8bd0c..b33ec14 100644 --- a/README.md +++ b/README.md @@ -54,14 +54,14 @@ pi=Pi() #connect to pigpiod daemon on localhost ## Example Usage ```julia -set_mode(p::Pi, pin::Int, mode) -get_mode(p::Pi, pin::Int) -# mode can be INPUT or OUTPUT +set_mode(pi::Pi, pin::Int, mode) +get_mode(pi::Pi, pin::Int) +# mode can be PiGPIO.INPUT or PiGPIO.OUTPUT -PiGPIO.read(p, pin) -PiGPIO.write(p, pin, state) -#state can be HIGH, LOW, ON, OFF +PiGPIO.read(pi, pin) +PiGPIO.write(pi, pin, state) +# state can be PiGPIO.HIGH, PiGPIO.LOW, PiGPIO.ON, PiGPIO.OFF -PiGPIO.set_PWM_dutycycle(p, pin, dutycyle) -#dutycyle defaults to a range 0-255 +PiGPIO.set_PWM_dutycycle(pi, pin, dutycyle) +# dutycyle defaults to a range 0-255 ``` From 33de9495b5152ed044953a3dd7a977c734d060da Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 16:42:08 +0000 Subject: [PATCH 26/51] add CI.yml --- .github/workflows/CI.yml | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..ff38214 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,73 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - 'lts' + - '1' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@latest + - run: | + git config --global user.name Tester + git config --global user.email te@st.er + - uses: julia-actions/julia-runtest@latest + continue-on-error: ${{ matrix.version == 'nightly' }} + # - uses: julia-actions/julia-processcoverage@v1 + # - uses: codecov/codecov-action@v4 + # with: + # file: lcov.info + # token: ${{ secrets.CODECOV_TOKEN }} + + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1' + - run: | + git config --global user.name name + git config --global user.email email + git config --global github.user username + - run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + Pkg.build()' + - run: | + julia --project=docs -e ' + using Documenter: doctest + using PiGPIO + doctest(PiGPIO)' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} From 08af51c27215cff2ff54820f37310d7e0609429e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 17:43:57 +0100 Subject: [PATCH 27/51] use Test module --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index c9d44cd..66993f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using PiGPIO +using Test # write your own tests here @test 1 == 1 From 436c4ca4a805bf1009d35dc59536c70dcc3d3f93 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 17:50:42 +0100 Subject: [PATCH 28/51] add test dependencies --- test/Project.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/Project.toml diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..ba693f5 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,3 @@ +[deps] +PiGPIO = "bb151fc1-c6dc-5496-8ed6-07f94907e623" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From d1a948e0ca319d320631e24b1c14a4546aa2a6cf Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 17:50:53 +0100 Subject: [PATCH 29/51] bump verion number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f79e1f7..477f661 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "PiGPIO" uuid = "bb151fc1-c6dc-5496-8ed6-07f94907e623" -version = "0.2.0" +version = "0.2.1" [compat] julia = "1" From 981839ff8eeaf2d7aead195cc46b1811cb418de8 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 18:00:42 +0100 Subject: [PATCH 30/51] deply docs --- docs/make.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 5cf55da..d71c57b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -25,9 +25,6 @@ makedocs( ] ) -# Documenter can also automatically deploy documentation to gh-pages. -# See "Hosting Documentation" and deploydocs() in the Documenter manual -# for more information. -#=deploydocs( - repo = "" -)=# +deploydocs(; + repo="github.com/JuliaBerry/PiGPIO.jl", +) From 05463e97dbeacec9f76c2cf8814f6d284c25ad9f Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 11 Nov 2024 18:05:34 +0100 Subject: [PATCH 31/51] add docs dev link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b33ec14..260d3e8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ #### Control GPIO pins on the Raspberry Pi from Julia [![][docs-stable-img]][docs-stable-url] +[![documentation dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaberry.github.io/PiGPIO.jl/dev/) [docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg [docs-stable-url]: https://juliahub.com/docs/PiGPIO/ From 4863f052c3bb73012cfc8a918181acbf39726865 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 08:19:52 +0100 Subject: [PATCH 32/51] remove unused Manifest.toml --- Manifest.toml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index de3b2cb..0000000 --- a/Manifest.toml +++ /dev/null @@ -1,2 +0,0 @@ -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" From c3c961d68e71b4852e4db154b90eef78119f781a Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 08:20:48 +0100 Subject: [PATCH 33/51] add Aqua tests --- Project.toml | 11 ++++++++++- test/Project.toml | 4 ++++ test/runtests.jl | 6 ++++-- test/test_aqua.jl | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/test_aqua.jl diff --git a/Project.toml b/Project.toml index 477f661..140882a 100644 --- a/Project.toml +++ b/Project.toml @@ -3,8 +3,17 @@ uuid = "bb151fc1-c6dc-5496-8ed6-07f94907e623" version = "0.2.1" [compat] -julia = "1" +Aqua = "0.8" Sockets = "1" +Test = "1" +julia = "1" [deps] Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" + +[extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Aqua", "Test"] diff --git a/test/Project.toml b/test/Project.toml index ba693f5..b6acad4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,3 +1,7 @@ [deps] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" PiGPIO = "bb151fc1-c6dc-5496-8ed6-07f94907e623" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +Aqua = "0.8" diff --git a/test/runtests.jl b/test/runtests.jl index 66993f2..c8a2405 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,7 @@ using PiGPIO using Test -# write your own tests here -@test 1 == 1 + +@testset "aqua checks" begin + include("test_aqua.jl") +end diff --git a/test/test_aqua.jl b/test/test_aqua.jl new file mode 100644 index 0000000..b47cbd3 --- /dev/null +++ b/test/test_aqua.jl @@ -0,0 +1,4 @@ +using Aqua +using PiGPIO + +Aqua.test_all(PiGPIO) From e900c2df1362de20af6636f8ca9de7cd602a005e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 08:39:00 +0100 Subject: [PATCH 34/51] Update README.md --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 260d3e8..9ca7ab0 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,18 @@ work is done by the daemon. One benefit of working this way is that you can remotely access the pi over a network and multiple instances can be connected to the daemon simultaneously. -## Launching the Daemon +## The daemon process `pigpiod` -Launching the daemon requires sudo privileges. Launch by typing `sudo pigpiod` -in the terminal. +On Raspberry Pi OS, the daemon `pigpiod` can be installed and launched by using the following shell commands: + +```bash +# install pigpiod +sudo apt-get install pigpiod +# enable pigpiod via system D +sudo systemctl enable pigpiod +``` + +The daemon can also be launched manually with `sudo pigpiod` in the terminal. ## Installation and Usage From 9efb42702cc9d01e2e5b159aae212c2a8c6db368 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 08:51:01 +0100 Subject: [PATCH 35/51] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ca7ab0..3d09c01 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,15 @@ Pkg.add("PiGPIO") using PiGPIO -pi=Pi() #connect to pigpiod daemon on localhost +pi=Pi() # connect to the pigpiod daemon on localhost ``` ## Example Usage +The `pin` number corresponds to the GPIO pins +(General Purpose Input/Output, aka "BCM" or "Broadcom") and not +to the physical pin numbers. + ```julia set_mode(pi::Pi, pin::Int, mode) get_mode(pi::Pi, pin::Int) From 559e6ea2eabd1e0b9273525d727f976b478a5eab Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 09:04:26 +0100 Subject: [PATCH 36/51] issue #3 --- src/PiGPIO.jl | 1 + src/pi.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PiGPIO.jl b/src/PiGPIO.jl index 15c1a8c..0437357 100644 --- a/src/PiGPIO.jl +++ b/src/PiGPIO.jl @@ -3,6 +3,7 @@ module PiGPIO export Pi +import Base: run using Sockets include("constants.jl") diff --git a/src/pi.jl b/src/pi.jl index e04a7c8..c25155a 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -220,7 +220,7 @@ end """Runs the notification thread.""" -function run(self::CallbackThread) +function Base.run(self::CallbackThread) lastLevel = _pigpio_command(self.control, _PI_CMD_BR1, 0, 0) MSG_SIZ = 12 while self.go From 17efccc412359dadb5d38b7a94b6308b7953c1d5 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 10:04:25 +0100 Subject: [PATCH 37/51] instantiate IOBuffer --- src/i2c.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 4787981..0f6a204 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -145,7 +145,7 @@ function i2c_write_byte_data(self::Pi, handle, reg, byte_val) # I p3 4 ## extension ## # I byte_val - extents = IOBuffer + extents = IOBuffer() write(extents, byte_val) return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_I2CWB, handle, reg, 4, extents)) @@ -178,7 +178,7 @@ function i2c_write_word_data(self::Pi, handle, reg, word_val) # I p3 4 ## extension ## # I word_val - extents = IOBuffer + extents = IOBuffer() write(extents, word_val) return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_I2CWW, handle, reg, 4, extents)) @@ -257,7 +257,7 @@ function i2c_process_call(self, handle, reg, word_val) # I p3 4 ## extension ## # I word_val - extents = IOBuffer + extents = IOBuffer() write(extents, word_val) return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_I2CPC, handle, reg, 4, extents)) From 849f3aaec3cb586910ed178e346e7f2f2d2727aa Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 10:49:59 +0100 Subject: [PATCH 38/51] avoid pack("I",...) --- src/i2c.jl | 6 +++++- src/wave.jl | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 0f6a204..caf20fa 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -41,7 +41,11 @@ function i2c_open(self::Pi, i2c_bus, i2c_address, i2c_flags=0) # I p3 4 ## extension ## # I i2c_flags - extents = [pack("I", i2c_flags)] + + io = IOBuffer() + write(io,Int32(i2c_flags)) + extents = take!(io) + return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents)) end diff --git a/src/wave.jl b/src/wave.jl index e291903..bc2c41a 100644 --- a/src/wave.jl +++ b/src/wave.jl @@ -94,13 +94,14 @@ function wave_add_generic(self::Pi, pulses) ## extension ## # III on/off/delay * pulses if length(pulses) - ext = bytearray() + io = IOBuffer() for p in pulses - ext.extend(pack("III", p.gpio_on, p.gpio_off, p.delay)) + # python's struct.pack("III",...) use 3 C unsigned int (normally 4-bytes) + write(io,Cuint.((p.gpio_on, p.gpio_off, p.delay))...) end - extents = [ext] + extents = take!(io) return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_WVAG, 0, 0, length(pulses)*12, extents)) + self.sl, _PI_CMD_WVAG, 0, 0, length(pulses)*3*4, extents)) else return 0 end @@ -147,9 +148,13 @@ wave_add_serial(pi, 17, 38400, [23, 128, 234], 5000) function wave_add_serial( self::Pi, user_gpio, baud, data, offset=0, bb_bits=8, bb_stop=2) if length(data) - extents = [pack("III", bb_bits, bb_stop, offset), data] + io = IOBuffer() + write(io,Cuint.((bb_bits, bb_stop, offset))...) + write(io,data) + + extents = take!(io) return _u2i(_pigpio_command_ext( - self.sl, _PI_CMD_WVAS, user_gpio, baud, length(data)+12, extents)) + self.sl, _PI_CMD_WVAS, user_gpio, baud, length(data)+3*4, extents)) else return 0 end From c80dd92841ef30217478f4ce96e43a2e380d02bf Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 10:56:06 +0100 Subject: [PATCH 39/51] do not convert elements of extents to string --- src/pi.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index c25155a..eb0ff95 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -123,11 +123,10 @@ Runs an extended pigpio socket command. * `extents`: additional data blocks """ function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=true) - ext = IOBuffer() - Base.write(ext, Array(reinterpret(UInt8, [cmd, p1, p2, p3]))) - for x in extents - write(ext, string(x)) - end + io = IOBuffer() + write(io,Cuint.((cmd, p1, p2, p3))...) + ext = vcat(take!(io),extents) + lock(sl.l) write(sl.s, ext) msg = reinterpret(Cuint, sl.s)[4] @@ -137,6 +136,10 @@ function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=true) return res end +function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents::IO, rl=true) + _pigpio_command_ext(sl, cmd, p1, p2, p3, take!(extents), rl) +end + """An ADT class to hold callback information * `gpio`: Broadcom GPIO number. From 38d9a5b6a97634cda2f1240ba8a906a5a8041282 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 11:31:44 +0100 Subject: [PATCH 40/51] use _SOCK_CMD_LEN=16 as in pigpio.py --- src/constants.jl | 2 ++ src/pi.jl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/constants.jl b/src/constants.jl index 6a51cd0..36bd581 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -57,6 +57,8 @@ WAVE_MODE_REPEAT_SYNC =3 WAVE_NOT_FOUND = 9998 # Transmitted wave not found. NO_TX_WAVE = 9999 # No wave being transmitted. +_SOCK_CMD_LEN = 16 + # pigpio command numbers _PI_CMD_MODES= 0 diff --git a/src/pi.jl b/src/pi.jl index eb0ff95..55000e0 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -104,7 +104,7 @@ Runs a pigpio socket command. function _pigpio_command(sl::SockLock, cmd::Integer, p1::Integer, p2::Integer, rl=true) lock(sl.l) Base.write(sl.s, UInt32.([cmd, p1, p2, 0])) - out = IOBuffer(Base.read(sl.s, 16)) + out = IOBuffer(Base.read(sl.s, _SOCK_CMD_LEN)) msg = reinterpret(Cuint, take!(out))[4] if rl unlock(sl.l) From 4e115ce460763c8da71a993fb2e2c07188d24c0e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Tue, 12 Nov 2024 11:37:38 +0100 Subject: [PATCH 41/51] use the same parsing of the return value as in the _pigpio_command (https://github.com/joan2937/pigpio/blob/c33738a320a3e28824af7807edafda440952c05d/pigpio.py#L1014) --- src/pi.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pi.jl b/src/pi.jl index 55000e0..5b59cf6 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -129,7 +129,8 @@ function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=true) lock(sl.l) write(sl.s, ext) - msg = reinterpret(Cuint, sl.s)[4] + out = IOBuffer(Base.read(sl.s, _SOCK_CMD_LEN)) + res = reinterpret(Cuint, take!(out))[4] if rl unlock(sl.l) end From b48be396080e3e9fbbfb670235e35d281c25a52c Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 11:44:57 +0100 Subject: [PATCH 42/51] extent write --- src/PiGPIO.jl | 2 +- src/spiSerial.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PiGPIO.jl b/src/PiGPIO.jl index 0437357..d63d6b9 100644 --- a/src/PiGPIO.jl +++ b/src/PiGPIO.jl @@ -3,7 +3,7 @@ module PiGPIO export Pi -import Base: run +import Base: run, write using Sockets include("constants.jl") diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 97ee12d..09b9377 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -89,7 +89,7 @@ function spi_open(self::Pi, spi_channel, baud, spi_flags=0) ## extension ## # I spi_flags extents=IOBuffer() - write(extents, spi_flags::Cint) + write(extents, Cint(spi_flags)) return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_SPIO, spi_channel, baud, 4, extents)) end From 5dc9f087bd434beecee967fd263a973fa2d6bc45 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 12:11:02 +0100 Subject: [PATCH 43/51] cast bb_bits to Cuint if necessary --- src/spiSerial.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 09b9377..94592da 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -383,7 +383,7 @@ function bb_serial_read_open(self, user_gpio, baud, bb_bits=8) ## extension ## # I bb_bits extents = IOBuffer() - write(extents, bb_bits::Cuint) + write(extents, Cuint(bb_bits)) return _u2i(_pigpio_command_ext( self.sl, _PI_CMD_SLRO, user_gpio, baud, 4, extents)) end From b91104cce66b42529ffab5f429dce734c984753e Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 12:16:16 +0100 Subject: [PATCH 44/51] add end for a if in the docstrings --- src/i2c.jl | 5 +++-- src/pi.jl | 14 ++++++++++---- src/spiSerial.jl | 11 +++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 0f6a204..091ad49 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -324,9 +324,10 @@ the error code). ```julia (b, d) = i2c_read_block_data(pi, h, 10) if b >= 0 -# process data + # process data else -# process read failure + # process read failure +end ``` """ function i2c_read_block_data(self::Pi, handle, reg) diff --git a/src/pi.jl b/src/pi.jl index c25155a..0223035 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -758,6 +758,7 @@ then GPIO x is high. h = notify_open(pi) if h >= 0 notify_begin(pi, h, 1234) +end ``` """ function notify_open(self::Pi) @@ -780,6 +781,7 @@ The following code starts notifications for GPIO 1, 4, h = notify_open(pi) if h >= 0 notify_begin(pi, h, 1234) +end ``` """ function notify_begin(self::Pi, handle, bits) @@ -803,6 +805,7 @@ if h >= 0 # ... notify_begin(pi, h, 1234) # ... +end ``` """ function notify_pause(self::Pi, handle) @@ -821,6 +824,7 @@ if h >= 0 # ... notify_close(pi, h) # ... +end ``` """ function notify_close(self::Pi, handle) @@ -1284,14 +1288,16 @@ otherwise false. ```julia if wait_for_edge(pi, 23) -print("Rising edge detected") + print("Rising edge detected") else -print("wait for edge timed out") + print("wait for edge timed out") +end if wait_for_edge(pi, 23, PiGPIO.FALLING_EDGE, 5.0) -print("Falling edge detected") + print("Falling edge detected") else -print("wait for falling edge timed out") + print("wait for falling edge timed out") +end ``` """ function wait_for_edge(self::Pi, user_gpio, edge=RISING_EDGE, wait_timeout=60.0) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 94592da..e93181b 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -121,9 +121,10 @@ the error code). ```julia (b, d) = spi_read(pi, h, 60) # read 60 bytes from device h if b == 60 -# process read data + # process read data else -# error path + # error path +end ``` """ function spi_read(self::Pi, handle, count) @@ -296,7 +297,8 @@ the error code). ```julia (b, d) = serial_read(pi, h2, 100) if b > 0 -# process read data + # process read data +end ``` """ function serial_read(self::Pi, handle, count) @@ -349,7 +351,8 @@ device associated with handle. rdy = serial_data_available(pi, h1) if rdy > 0 -(b, d) = serial_read(pi, h1, rdy) + (b, d) = serial_read(pi, h1, rdy) +end ``` """ function serial_data_available(self::Pi, handle) From 3cb7be068c7daee4989f408dae204107303c0003 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 14:45:16 +0100 Subject: [PATCH 45/51] add end for an if in the docstrings --- src/i2c.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 091ad49..6d5bd0d 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -453,9 +453,10 @@ the error code). ```julia (b, d) = i2c_read_i2c_block_data(pi, h, 4, 32) if b >= 0 -# process data + # process data else -# process read failure + # process read failure +end ``` """ function i2c_read_i2c_block_data(self::Pi, handle, reg, count) From 10850d256f99ee1151cf6b1e8fb88058e4568d66 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 16:45:02 +0100 Subject: [PATCH 46/51] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3d09c01..1f59db0 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ On Raspberry Pi OS, the daemon `pigpiod` can be installed and launched by using sudo apt-get install pigpiod # enable pigpiod via system D sudo systemctl enable pigpiod +# start pigpiod now +sudo systemctl start pigpiod ``` The daemon can also be launched manually with `sudo pigpiod` in the terminal. From 34866ff6968ae1e6111119c3e5eebe55014ad7bb Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 19 Dec 2024 17:00:54 +0100 Subject: [PATCH 47/51] fix error messages #13 --- src/pi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pi.jl b/src/pi.jl index 0223035..8998c1e 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -71,7 +71,7 @@ is negative it indicates an error. On error a pigpio exception will be raised if exceptions is true. """ function _u2i(x::UInt32) - v = convert(Int32, x) + v = reinterpret(Int32, x) if v < 0 if exceptions error(error_text(v)) From ea8de2856e094f7bf1997225234e1fe7bc49b3da Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 23 Dec 2024 13:39:52 +0100 Subject: [PATCH 48/51] rxbuf requires two arguments (issue #19) --- src/i2c.jl | 6 +++--- src/pi.jl | 2 +- src/spiSerial.jl | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/i2c.jl b/src/i2c.jl index 4305907..a4ecc07 100644 --- a/src/i2c.jl +++ b/src/i2c.jl @@ -338,7 +338,7 @@ function i2c_read_block_data(self::Pi, handle, reg) # Don't raise exception. Must release lock. bytes = u2i(_pigpio_command(self.sl, _PI_CMD_I2CRK, handle, reg, false)) if bytes > 0 - data = rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end @@ -614,7 +614,7 @@ function i2c_zip(self::Pi, handle, data) bytes = u2i(_pigpio_command_ext( self.sl, _PI_CMD_I2CZ, handle, 0, length(data), data, false)) if bytes > 0 - data = self._rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end @@ -756,7 +756,7 @@ function bb_i2c_zip(self::Pi, SDA, data) bytes = u2i(_pigpio_command_ext( self.sl, _PI_CMD_BI2CZ, SDA, 0, length(data), [data], false)) if bytes > 0 - data = self._rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end diff --git a/src/pi.jl b/src/pi.jl index 355d56c..133dfd6 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -1218,7 +1218,7 @@ function custom_2(self, arg1=0, argx=[], retMax=8192) bytes = u2i(_pigpio_command_ext( self.sl, _PI_CMD_CF2, arg1, retMax, length(argx), [argx], false)) if bytes > 0 - data = rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end diff --git a/src/spiSerial.jl b/src/spiSerial.jl index e93181b..15a45d9 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -132,7 +132,7 @@ function spi_read(self::Pi, handle, count) bytes = u2i(_pigpio_command( self.sl, _PI_CMD_SPIR, handle, count, false)) if bytes > 0 - data = rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end @@ -195,11 +195,14 @@ function spi_xfer(self::Pi, handle, data) ## extension ## # s len data bytes + # python code + # https://github.com/joan2937/pigpio/blob/c33738a320a3e28824af7807edafda440952c05d/pigpio.py#L4045 + # Don't raise exception. Must release lock. bytes = u2i(_pigpio_command_ext( self.sl, _PI_CMD_SPIX, handle, 0, length(data), data, false)) if bytes > 0 - data = rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end @@ -306,7 +309,7 @@ function serial_read(self::Pi, handle, count) bytes = u2i( _pigpio_command(self.sl, _PI_CMD_SERR, handle, count, false)) if bytes > 0 - data = rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end @@ -418,7 +421,7 @@ function bb_serial_read(self, user_gpio) bytes = u2i( _pigpio_command(self.sl, _PI_CMD_SLR, user_gpio, 10000, false)) if bytes > 0 - data = self._rxbuf(bytes) + data = rxbuf(self,bytes) else data = "" end From 8c2cbf1d7c4ff5083ed8e4d7593113ee2553afb0 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 23 Dec 2024 13:46:58 +0100 Subject: [PATCH 49/51] add missing u2i function (thanks @TheCedarPrince) --- src/pi.jl | 2 ++ test/runtests.jl | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/pi.jl b/src/pi.jl index 133dfd6..07e4b60 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -64,6 +64,7 @@ function tickDiff(t1, t2) return tDiff end +u2i(x::UInt32) = signed(x) """ Converts a 32 bit unsigned number to signed. If the number @@ -81,6 +82,7 @@ function _u2i(x::UInt32) end + struct InMsg cmd::Cuint # a bits type p1::Cuint # an array of bits types diff --git a/test/runtests.jl b/test/runtests.jl index c8a2405..4c70b5f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,15 @@ using PiGPIO using Test +using PiGPIO: u2i + + +@testset "utility functions" begin + # https://github.com/joan2937/pigpio/blob/c33738a320a3e28824af7807edafda440952c05d/pigpio.py#L989 + + @test u2i(UInt32(4294967272)) == -24 + @test u2i(UInt32(37)) == 37 +end @testset "aqua checks" begin include("test_aqua.jl") From 1b1a638bdb2e5ea1217dfcb0e98fcf96c94fe5e5 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 23 Dec 2024 15:26:49 +0000 Subject: [PATCH 50/51] remove unnessary wrapping of output with IOBuffer --- src/pi.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pi.jl b/src/pi.jl index 07e4b60..bcac243 100644 --- a/src/pi.jl +++ b/src/pi.jl @@ -106,8 +106,10 @@ Runs a pigpio socket command. function _pigpio_command(sl::SockLock, cmd::Integer, p1::Integer, p2::Integer, rl=true) lock(sl.l) Base.write(sl.s, UInt32.([cmd, p1, p2, 0])) - out = IOBuffer(Base.read(sl.s, _SOCK_CMD_LEN)) - msg = reinterpret(Cuint, take!(out))[4] + + out = Base.read(sl.s, _SOCK_CMD_LEN) + @debug "_pigpio_command" out + msg = reinterpret(Cuint, out)[4] if rl unlock(sl.l) end @@ -131,8 +133,9 @@ function _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=true) lock(sl.l) write(sl.s, ext) - out = IOBuffer(Base.read(sl.s, _SOCK_CMD_LEN)) - res = reinterpret(Cuint, take!(out))[4] + out = Base.read(sl.s, _SOCK_CMD_LEN) + @debug "_pigpio_command_ext" out ext + res = reinterpret(Cuint, out)[4] if rl unlock(sl.l) end From 81a1347e0d83775431d8c61b70ef0235bb6c0b87 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Mon, 23 Dec 2024 15:27:05 +0000 Subject: [PATCH 51/51] formatting --- src/spiSerial.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spiSerial.jl b/src/spiSerial.jl index 15a45d9..3db47cf 100644 --- a/src/spiSerial.jl +++ b/src/spiSerial.jl @@ -200,7 +200,7 @@ function spi_xfer(self::Pi, handle, data) # Don't raise exception. Must release lock. bytes = u2i(_pigpio_command_ext( - self.sl, _PI_CMD_SPIX, handle, 0, length(data), data, false)) + self.sl, _PI_CMD_SPIX, handle, 0, length(data), data, false)) if bytes > 0 data = rxbuf(self,bytes) else