aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-03-17 01:01:51 +0000
committerPaul Oliver <contact@pauloliver.dev>2025-03-17 01:39:21 +0000
commit234d21167e5ca45b8a2665df52dcf0cdb48f3dc0 (patch)
tree9884e1706763fc70db9480472ba87a75da9cd9b8
parent0be7f1274e0cb8406bd4262b86d5e2e9dda77d7a (diff)
(WIP) Camera serviceHEADmaster
-rw-r--r--hsm-cam/Hsm/Cam.hs3
-rw-r--r--hsm-cam/Hsm/Cam/Lib.cpp11
-rw-r--r--hsm-cam/Hsm/Cam/Lib.hsc20
-rw-r--r--hsm-cam/hsm-cam.cabal22
-rw-r--r--stack.yaml1
-rw-r--r--sysconf/97-libcamera.rules5
6 files changed, 62 insertions, 0 deletions
diff --git a/hsm-cam/Hsm/Cam.hs b/hsm-cam/Hsm/Cam.hs
new file mode 100644
index 0000000..ef99e82
--- /dev/null
+++ b/hsm-cam/Hsm/Cam.hs
@@ -0,0 +1,3 @@
+module Hsm.Cam
+ (
+ ) where
diff --git a/hsm-cam/Hsm/Cam/Lib.cpp b/hsm-cam/Hsm/Cam/Lib.cpp
new file mode 100644
index 0000000..5eda6d7
--- /dev/null
+++ b/hsm-cam/Hsm/Cam/Lib.cpp
@@ -0,0 +1,11 @@
+#include <string>
+
+#include "Lib_stub.h"
+
+void log_msg(const std::string &str) {
+ logMsg((HsPtr)str.c_str());
+}
+
+extern "C" void some_c_wrapper() {
+ log_msg("Hello from C++!");
+}
diff --git a/hsm-cam/Hsm/Cam/Lib.hsc b/hsm-cam/Hsm/Cam/Lib.hsc
new file mode 100644
index 0000000..4f6dadf
--- /dev/null
+++ b/hsm-cam/Hsm/Cam/Lib.hsc
@@ -0,0 +1,20 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE OverloadedStrings #-}
+
+module Hsm.Cam.Lib
+ ( someCWrapper
+ ) where
+
+import Control.Monad ((>=>))
+import Data.Text (pack)
+import Foreign.C.String (CString, peekCString)
+import Hsm.Log qualified as L
+
+foreign export ccall logMsg :: CString -> IO ()
+
+logMsg :: CString -> IO ()
+logMsg = peekCString >=> L.logMsg ["cam", "lib"] . pack
+
+foreign import ccall safe "Test.h some_c_wrapper"
+ someCWrapper :: IO ()
diff --git a/hsm-cam/hsm-cam.cabal b/hsm-cam/hsm-cam.cabal
new file mode 100644
index 0000000..1f732e9
--- /dev/null
+++ b/hsm-cam/hsm-cam.cabal
@@ -0,0 +1,22 @@
+cabal-version: 3.4
+author: Paul Oliver
+build-type: Simple
+maintainer: contact@pauloliver.dev
+name: hsm-cam
+version: 0.1.0.0
+extra-source-files: Hsm/Cam/*.cpp
+
+library
+ build-depends:
+ , base
+ , hsm-log
+ , text
+
+ exposed-modules: Hsm.Cam
+ other-modules: Hsm.Cam.Lib
+ include-dirs: Hsm/Cam
+ cxx-sources: Hsm/Cam/Lib.cpp
+ cxx-options: -Wall -Wextra -O2
+ ghc-options: -Wall -Wunused-packages
+ extra-libraries: stdc++
+ default-language: GHC2021
diff --git a/stack.yaml b/stack.yaml
index 0fda386..8a99d38 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -1,5 +1,6 @@
packages:
- hsm-bin
+ - hsm-cam
- hsm-drive
- hsm-gpio
- hsm-log
diff --git a/sysconf/97-libcamera.rules b/sysconf/97-libcamera.rules
new file mode 100644
index 0000000..d92e2b4
--- /dev/null
+++ b/sysconf/97-libcamera.rules
@@ -0,0 +1,5 @@
+# This rule grants the `video` group access to GPIO the `dma_heap` subsystem.
+# This facilitates video streaming using the Raspberry Pi camera module.
+SUBSYSTEM=="dma_heap",KERNEL=="linux*",GROUP="video",MODE="0660"
+SUBSYSTEM=="dma_heap",KERNEL=="reserved",GROUP="video",MODE="0660"
+SUBSYSTEM=="dma_heap",KERNEL=="system",GROUP="video",MODE="0660"