chiark / gitweb /
wiringpi: much implementation, move pwmc/pwmr
[chiark-tcl.git] / wiringpi / wiringpi.c
index 5cc774d..3b6348d 100644 (file)
@@ -125,20 +125,6 @@ int cht_do_wiringpitcl_setup(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
-int cht_do_wiringpitcl_pwmc(ClientData cd, Tcl_Interp *ip, int divider) {
-  CHECK_SETUP;
-  CHECK_RANGE(divider,1,4095,"divider for pwmc","DIVIDER");
-  pwmSetClock(divider);
-  return TCL_OK;
-}
-
-int cht_do_wiringpitcl_pwmr(ClientData cd, Tcl_Interp *ip, int range) {
-  CHECK_SETUP;
-  CHECK_RANGE(range,1,INT_MAX,"pwm range","RANGE");
-  pwmSetRange(range);
-  return TCL_OK;
-}
-
 int cht_do_wiringpitcl_boardId(ClientData cd, Tcl_Interp *ip,
                               Tcl_Obj **result) {
 #define N 5
@@ -163,14 +149,33 @@ int cht_do_wiringpitcl_boardRev(ClientData cd, Tcl_Interp *ip, int *result) {
   return TCL_OK;
 }
 
-/*---------- families operations ----------*/
+int cht_do_wiringpitcl_pwmc(ClientData cd, Tcl_Interp *ip, int divider) {
+  CHECK_SETUP;
+  CHECK_RANGE(divider,1,4095,"divider for pwmc","DIVIDER");
+  pwmSetClock(divider);
+  return TCL_OK;
+}
 
-int cht_do_wiringpitcl_aread(ClientData cd, Tcl_Interp *ip, int pin, int *result) {
+int cht_do_wiringpitcl_pwmr(ClientData cd, Tcl_Interp *ip, int range) {
   CHECK_SETUP;
-  *result = analogRead(pin);
+  CHECK_RANGE(range,1,INT_MAX,"pwm range","RANGE");
+  pwmSetRange(range);
   return TCL_OK;
 }
 
+/*---------- families of operations ----------*/
+
+#define SIMPLE_READER_OP(op, wpicall)                          \
+  int cht_do_wiringpitcl_##op(ClientData cd, Tcl_Interp *ip,   \
+                               int pin, int *result) {         \
+    CHECK_SETUP;                                               \
+    *result = wpicall(pin);                                    \
+    return TCL_OK;                                             \
+  }
+
+SIMPLE_READER_OP(read,  digitalRead)
+SIMPLE_READER_OP(aread, analogRead)
+
 #define SIMPLE_WRITER_OP(op, min, max, wpicall)                        \
   int cht_do_wiringpitcl_##op(ClientData cd, Tcl_Interp *ip,   \
                              int pin, int val) {               \