]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/sfunction_gio_in.c
gio blocks: Allow users to select the pin from a list
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_gio_in.c
index 168fbb9c9a839d9289fa34e3b1b4c38d02037e30..00238c68af677728cb22bd07426b049e1c2a250c 100644 (file)
@@ -33,26 +33,26 @@ Inputs:
 Outputs:
   - { name: "Digital Input value", type: "bool" }
 Parameters:
-  - { name: "Port type", type: "Choice", range: "GIOA, GIOB, NHET1" }
-  - { name: "Pin number", type: "int8",   range: "[0–7]", note: "(depends on selected port)" }
+  - { name: "Pin", type: "Choice", range: "Target dependent pin names or '---'" }
+  - { name: "Pin name", type: "String", note: "Pin name as defined in gio_def.h. This parameter is only visible if *Pin* is '---'." }
   - { name: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" }
 
 # Description is in Markdown mark-up
 Description: &desc |
-  Reads a value from a GPIO pin. The block supports GIOA, GIOB and NHET1 ports.
-  Any pin can be configured as tri-state, pull up or pull down.
+  Reads value from a GIO pin. Which pins are supported depends on the
+  target board. The selected pin can be configured as tri-state, pull
+  up or pull down.
 
-  It is not allowed to read from one pin by using more then one GIOIN blocks.
-  It is not allowed to use GIOIN and DOUT blocks together configured for one GPIO pin.
+  When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
+  signaled.
 
 Help: *desc
 
 Status: Stable
 
 RPP API functions used:
-  - hal_gpio_pin_get_dsc
-  - hal_gpio_pin_get_value
-  - hal_gpio_pin_conf_set
+  - rpp_gio_setup
+  - rpp_gio_get
 
 Relevant demos:
   - gio_demo
@@ -63,25 +63,13 @@ Relevant demos:
 #define S_FUNCTION_NAME sfunction_gio_in
 #include "header.c"
 
-#define PARAM_NAME_PORT_TYPE           "port_type"
-#define PARAM_NAME_PIN_NUMBER          "pin_number"
-#define PARAM_NAME_INPUT_TYPE          "input_type"
-
 /** Identifiers of the block parameters */
 enum params{
-       PARAM_PORT_TYPE,
-       PARAM_PIN_NUMBER,
+       PARAM_PIN_NAME,
        PARAM_INPUT_TYPE,
        PARAMS_COUNT
 };
 
-enum port_types{
-       PORT_UNKNOWN,
-       PORT_GIOA,
-       PORT_GIOB,
-       PORT_NHET1
-};
-
 enum outputs{
        OUT_PIN_VALUE,
        OUTPUTS_COUNT
@@ -89,12 +77,6 @@ enum outputs{
 
 static void mdlInitializeSizes(SimStruct *S)
 {
-       /*
-       * Configure parameters: 3
-       *  - Port type
-       *  - Pin number
-       *  - Input type
-       */
        if (!rppSetNumParams(S, PARAMS_COUNT)) {
                return;
        }
@@ -123,42 +105,33 @@ static void mdlInitializeSizes(SimStruct *S)
 #define MDL_CHECK_PARAMETERS
 static void mdlCheckParameters(SimStruct *S)
 {
-       if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) {
-               if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
-                       return;
-               }
-       }
-       else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) {
-               if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
-                       return;
-               }
-       }
-       else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) {
-               if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) {
-                       return;
-               }
-       }
-       else {
-               return;
-       }
+    if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
+        ssSetErrorStatus(S, "Parameter to S-function must be a string.");
+    }
 }
 #endif
 
 
-#ifdef MATLAB_MEX_FILE
-#define MDL_SET_WORK_WIDTHS
-static void mdlSetWorkWidths(SimStruct *S)
+#if defined(MATLAB_MEX_FILE)
+#define MDL_RTW
+static void mdlRTW(SimStruct *S)
 {
-       /* Set number of run-time parameters */
-       if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) {
-               return;
-       }
-       /* Register the run-time parameter 1 */
-       ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE,      PARAM_PORT_TYPE,      PARAM_NAME_PORT_TYPE,      SS_INT8);
-       ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER,     PARAM_PIN_NUMBER,     PARAM_NAME_PIN_NUMBER,     SS_INT8);
-       ssRegDlgParamAsRunTimeParam(S, PARAM_INPUT_TYPE,     PARAM_INPUT_TYPE,     PARAM_NAME_INPUT_TYPE,     SS_INT8);
+    char_T pin_name[80];
+    int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0];
+
+    if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
+        ssSetErrorStatus(S,"mxGetString error in mdlRTW");
+        return;
+    }
+
+    if (!ssWriteRTWParamSettings(S, 2,
+                                 SSWRITE_VALUE_STR, "PinName", pin_name,
+                                 SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) {
+        ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
+    }
 }
-#endif
+#endif /* MDL_RTW */
+
 
 
 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT