summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp4
-rw-r--r--signal-composer-binding/signal-composer.cpp62
-rw-r--r--signal-composer-binding/signal.cpp139
-rw-r--r--signal-composer-binding/signal.hpp45
-rw-r--r--signal-composer-binding/source.cpp2
5 files changed, 102 insertions, 150 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 0d9c8e3..f7c8c73 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -32,10 +32,8 @@
/// @param[in] object - eventual data that comes with the event
void onEvent(const char *event, json_object *object)
{
- Composer& composer = Composer::instance();
- AFB_NOTICE("event: %s", json_object_to_json_string(object));
+ std::vector<std::shared_ptr<Signal>> signals { Composer::instance().searchSignals(event) };
- std::vector<std::shared_ptr<Signal>> signals = composer.searchSignals(event);
if(!signals.empty())
{
// If there is more than 1 element then maybe we can find a more
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 99129b4..f7c1971 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -21,7 +21,7 @@
#include "clientApp.hpp"
-extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, struct signalValue value)
+extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, json_object* value)
{
std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(aName);
if(!signals.empty())
@@ -31,7 +31,7 @@ extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestam
}
}
-extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, struct signalValue value)
+extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, json_object* value)
{
Signal* sig = static_cast<Signal*>(aSignal);
sig->set(timestamp, value);
@@ -380,47 +380,25 @@ void Composer::processOptions(const std::map<std::string, int>& opts, std::share
{
avg = true;
double value = sig->average(o.second);
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("minimum") && !min)
{
min = true;
double value = sig->minimum();
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("maximum") && !max)
{
max = true;
double value = sig->maximum();
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("last") && !last)
{
last = true;
- struct signalValue value = sig->last_value();
- if(value.hasBool)
- {
- json_object_object_add(response, "value",
- json_object_new_boolean(value.boolVal));
- }
- else if(value.hasNum)
- {
- json_object_object_add(response, "value",
- json_object_new_double(value.numVal));
- }
- else if(value.hasStr)
- {
- json_object_object_add(response, "value",
- json_object_new_string(value.strVal.c_str()));
- }
- else
- {
- json_object_object_add(response, "value",
- json_object_new_string("No recorded value so far."));
- }
+ json_object* value = sig->last_value();
+ json_object_object_add(response, "value", value);
}
else
{
@@ -568,8 +546,9 @@ std::vector<std::shared_ptr<Signal>> Composer::searchSignals(const std::string&
if(sep != std::string::npos)
{
api = aName.substr(0, sep);
+ std::string signal_id = aName.substr(sep + 1, std::string::npos);
std::shared_ptr<SourceAPI> source = getSourceAPI(api);
- return source->searchSignals(aName);
+ return source->searchSignals(signal_id);
}
else
{
@@ -603,27 +582,8 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio
"signal", sig->id().c_str());
if (opts.empty())
{
- struct signalValue value = sig->last_value();
- if(value.hasBool)
- {
- json_object_object_add(response, "value",
- json_object_new_boolean(value.boolVal));
- }
- else if(value.hasNum)
- {
- json_object_object_add(response, "value",
- json_object_new_double(value.numVal));
- }
- else if(value.hasStr)
- {
- json_object_object_add(response, "value",
- json_object_new_string(value.strVal.c_str()));
- }
- else
- {
- json_object_object_add(response, "value",
- json_object_new_string("No recorded value so far."));
- }
+ json_object* value = sig->last_value();
+ json_object_object_add(response, "value", value);
}
else
{processOptions(opts, sig, response);}
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 2f1aa57..14e85ba 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -148,9 +148,8 @@ json_object* Signal::toJSON() const
if(timestamp_)
json_object_object_add(sigJ, "timestamp", json_object_new_int64(timestamp_));
- if (value_.hasBool) {json_object_object_add(sigJ, "value", json_object_new_boolean(value_.boolVal));}
- else if (value_.hasNum) {json_object_object_add(sigJ, "value", json_object_new_double(value_.numVal));}
- else if (value_.hasStr) {json_object_object_add(sigJ, "value", json_object_new_string(value_.strVal.c_str()));}
+ if(value_)
+ json_object_object_add(sigJ, "value", value_);
return sigJ;
}
@@ -198,19 +197,21 @@ json_object *Signal::getSignalsArgs()
///
/// @param[in] timestamp - timestamp of occured signal
/// @param[in] value - value of change
-void Signal::set(uint64_t timestamp, struct signalValue& value)
+void Signal::set(uint64_t timestamp, json_object*& value)
{
uint64_t diff = retention_+1;
value_ = value;
timestamp_ = timestamp;
- history_[timestamp_] = value_;
+ history_[timestamp_] = json_object_get(value_);
while(diff > retention_)
{
uint64_t first = history_.begin()->first;
diff = (timestamp_ - first)/NANO;
- if(diff > retention_)
- {history_.erase(history_.cbegin());}
+ if(diff > retention_) {
+ json_object_put(history_.cbegin()->second);
+ history_.erase(history_.cbegin());
+ }
}
notify();
@@ -253,37 +254,22 @@ void Signal::update(Signal* sig)
/// @param[in] eventJ - json_object containing event data to process
///
/// @return 0 if ok, -1 or others if not
-void Signal::defaultReceivedCB(json_object *eventJ)
+void Signal::defaultReceivedCB(Signal *signal, json_object *eventJ)
{
uint64_t ts = 0;
- struct signalValue sv;
+ json_object* sv = nullptr;
json_object_iterator iter = json_object_iter_begin(eventJ);
json_object_iterator iterEnd = json_object_iter_end(eventJ);
+
while(!json_object_iter_equal(&iter, &iterEnd))
{
std::string key = json_object_iter_peek_name(&iter);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
json_object *value = json_object_iter_peek_value(&iter);
if (key.find("value") != std::string::npos ||
- key.find(id_) != std::string::npos)
+ key.find(signal->id()) != std::string::npos)
{
- switch (json_object_get_type(value)) {
- case json_type_double:
- sv = json_object_get_double(value);
- break;
- case json_type_int:
- sv = json_object_get_int(value);
- break;
- case json_type_boolean:
- sv = json_object_get_int(value);
- break;
- case json_type_string:
- sv = json_object_get_string(value);
- break;
- default:
- sv = signalValue();
- break;
- }
+ sv = json_object_get(value);
}
else if (key.find("timestamp") != std::string::npos)
{
@@ -292,9 +278,9 @@ void Signal::defaultReceivedCB(json_object *eventJ)
json_object_iter_next(&iter);
}
- if(!sv.hasBool && !sv.hasNum && !sv.hasStr)
+ if(!sv)
{
- AFB_ERROR("No data found to set signal %s in %s", id_.c_str(), json_object_to_json_string(eventJ));
+ AFB_ERROR("No data found to set signal %s in %s", signal->id().c_str(), json_object_to_json_string(eventJ));
return;
}
else if(ts == 0)
@@ -305,7 +291,7 @@ void Signal::defaultReceivedCB(json_object *eventJ)
ts = (uint64_t)(t.tv_sec) * (uint64_t)NANO + (uint64_t)(t.tv_nsec);
}
- set(ts, sv);
+ signal->set(ts, sv);
}
/// @brief Notify observers that there is a change and execute callback defined
@@ -343,7 +329,7 @@ void Signal::onReceivedCB(json_object *eventJ)
if (onReceived_)
ActionExecOne(&source, onReceived_, json_object_get(eventJ));
else
- defaultReceivedCB(eventJ);
+ defaultReceivedCB(this, eventJ);
}
/// @brief Make a Signal observer observes Signals observables
@@ -382,22 +368,31 @@ double Signal::average(int seconds) const
double total = 0.0;
int nbElt = 0;
- for (const auto& val: history_)
+ for(const auto& val: history_)
{
- if(val.first >= end)
- {break;}
- if(val.second.hasNum)
+ if(val.first >= end) {
+ break;
+ }
+ if(val.second)
{
- total += val.second.numVal;
+ switch(json_object_get_type(val.second)) {
+ case json_type_int:
+ total += static_cast<double>(json_object_get_int64(val.second));
+ break;
+ case json_type_double:
+ total += json_object_get_double(val.second);
+ break;
+ default:
+ AFB_ERROR("The stored value '%s' for the signal '%s' isn't numeric, it is not possible to compute an average value.", json_object_get_string(val.second), id_.c_str());
+ break;
+ }
nbElt++;
}
else
{
- AFB_ERROR("There isn't numerical value to compare with in that signal '%s'. Stored value : bool %d, num %lf, str: %s",
+ AFB_ERROR("There isn't numerical value to compare with in that signal '%s'. Stored value: %s",
id_.c_str(),
- val.second.boolVal,
- val.second.numVal,
- val.second.strVal.c_str());
+ json_object_get_string(val.second));
break;
}
}
@@ -416,21 +411,34 @@ double Signal::minimum(int seconds) const
uint64_t end = seconds ?
begin+(seconds*NANO) :
history_.rbegin()->first;
+ double current = 0.0;
double min = DBL_MAX;
- for (auto& v : history_)
+ for(const auto& val : history_)
{
- if(v.first >= end)
- {break;}
- else if(v.second.hasNum && v.second.numVal < min)
- {min = v.second.numVal;}
+ if(val.first >= end) {
+ break;
+ }
+ else if(val.second) {
+ switch(json_object_get_type(val.second)) {
+ case json_type_int:
+ current = static_cast<double>(json_object_get_int64(val.second));
+ min = current < min ? current : min;
+ break;
// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2004
 * Pierre Aubert, Staubli Faverges , <p.aubert@staubli.com>
 * Copyright 2011 Freescale Semiconductor, Inc.
 */

/************************************************************************
  Get Parameters for the video mode:
  The default video mode can be defined in CONFIG_SYS_DEFAULT_VIDEO_MODE.
  If undefined, default video mode is set to 0x301
  Parameters can be set via the variable "videomode" in the environment.
  2 diferent ways are possible:
  "videomode=301"   - 301 is a hexadecimal number describing the VESA
		      mode. Following modes are implemented:

		      Colors	640x480 800x600 1024x768 1152x864 1280x1024
		     --------+---------------------------------------------
		      8 bits |	0x301	0x303	 0x305	  0x161	    0x307
		     15 bits |	0x310	0x313	 0x316	  0x162	    0x319
		     16 bits |	0x311	0x314	 0x317	  0x163	    0x31A
		     24 bits |	0x312	0x315	 0x318	    ?	    0x31B
		     --------+---------------------------------------------
  "videomode=bootargs"
		   - the parameters are parsed from the bootargs.
		      The format is "NAME:VALUE,NAME:VALUE" etc.
		      Ex.:
		      "bootargs=video=ctfb:x:800,y:600,depth:16,pclk:25000"
		      Parameters not included in the list will be taken from
		      the default mode, which is one of the following:
		      mode:0  640x480x24
		      mode:1  800x600x16
		      mode:2  1024x768x8
		      mode:3  960x720x24
		      mode:4  1152x864x16
		      mode:5  1280x1024x8

		      if "mode" is not provided within the parameter list,
		      mode:0 is assumed.
		      Following parameters are supported:
		      x	      xres = visible resolution horizontal
		      y	      yres = visible resolution vertical
		      pclk    pixelclocks in pico sec
		      le      left_marging time from sync to picture in pixelclocks
		      ri      right_marging time from picture to sync in pixelclocks
		      up      upper_margin time from sync to picture
		      lo      lower_margin
		      hs      hsync_len length of horizontal sync
		      vs      vsync_len length of vertical sync
		      sync    see FB_SYNC_*
		      vmode   see FB_VMODE_*
		      depth   Color depth in bits per pixel
		      All other parameters in the variable bootargs are ignored.
		      It is also possible to set the parameters direct in the
		      variable "videomode", or in another variable i.e.
		      "myvideo" and setting the variable "videomode=myvideo"..
****************************************************************************/

#include <common.h>
#include <edid.h>
#include <env.h>
#include <errno.h>
#include <fdtdec.h>
#include <linux/ctype.h>

#include "videomodes.h"

const struct ctfb_vesa_modes vesa_modes[VESA_MODES_COUNT] = {
	{0x301, RES_MODE_640x480, 8},
	{0x310, RES_MODE_640x480, 15},
	{0x311, RES_MODE_640x480, 16},
	{0x312, RES_MODE_640x480, 24},
	{0x303, RES_MODE_800x600, 8},
	{0x313, RES_MODE_800x600, 15},
	{0x314, RES_MODE_800x600, 16},
	{0x315, RES_MODE_800x600, 24},
	{
+extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, json_object* value);
/// @brief Holds composer callbacks and obj to manipulate
struct signalCBT
{
- void (*searchNsetSignalValue)(const char* aName, uint64_t timestamp, struct signalValue value);
- void (*setSignalValue)(void* aSignal, uint64_t timestamp, struct signalValue value);
+ void (*searchNsetSignalValue)(const char* aName, uint64_t timestamp, json_object* value);
+ void (*setSignalValue)(void* aSignal, uint64_t timestamp, json_object* value);
void* aSignal;
void* pluginCtx;
};
@@ -80,8 +54,8 @@ private:
std::string event_;
std::vector<std::string> dependsSigV_;
uint64_t timestamp_;
- struct signalValue value_;
- std::map<uint64_t, struct signalValue> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
+ json_object* value_;
+ std::map<uint64_t, json_object*> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
int retention_;
double frequency_;
std::string unit_;
@@ -107,17 +81,16 @@ public:
struct signalCBT* get_context();
json_object *getSignalsArgs();
- void set(uint64_t timestamp, struct signalValue& value);
+ void set(uint64_t timestamp, json_object*& value);
void update(Signal* sig);
- static int defaultOnReceivedCB(CtlSourceT* source, json_object* argsJ, json_object *queryJ);
- void defaultReceivedCB(json_object *eventJ);
+ static void defaultReceivedCB(Signal *signal, json_object *eventJ);
void onReceivedCB(json_object *eventJ);
void attachToSourceSignals(Composer& composer);
double average(int seconds = 0) const;
double minimum(int seconds = 0) const;
double maximum(int seconds = 0) const;
- struct signalValue last_value() const;
+ json_object* last_value() const;
uint64_t last_timestamp() const;
int initialRecursionCheck();
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index a46e766..bd988c9 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -122,7 +122,7 @@ std::vector<std::shared_ptr<Signal>> SourceAPI::searchSignals(const std::string&
if(signalsM_.count(name))
{signals.emplace_back(signalsM_[name]);}
- if(newSignalsM_.count(name))
+ else if(newSignalsM_.count(name))
{signals.emplace_back(signalsM_[name]);}
else
{
span class="p">, 720, 80, 13100, 76335, 160, 40, 32, 8, 80, 4, 0, FB_VMODE_NONINTERLACED}, {1152, 864, 60, 12004, 83300, 200, 64, 32, 16, 80, 4, 0, FB_VMODE_NONINTERLACED}, {1280, 1024, 60, 9090, 110000, 200, 48, 26, 1, 184, 3, 0, FB_VMODE_NONINTERLACED}, #else { 640, 480, 60, 39683, 25200, 48, 16, 33, 10, 96, 2, 0, FB_VMODE_NONINTERLACED}, { 800, 600, 60, 25000, 40000, 88, 40, 23, 1, 128, 4, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED}, {1024, 768, 60, 15384, 65000, 160, 24, 29, 3, 136, 6, 0, FB_VMODE_NONINTERLACED}, { 960, 720, 75, 13468, 74250, 176, 72, 27, 1, 112, 2, 0, FB_VMODE_NONINTERLACED}, {1152, 864, 75, 9259, 108000, 256, 64, 32, 1, 128, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED}, {1280, 1024, 60, 9259, 108000, 248, 48, 38, 1, 112, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED}, #endif {1280, 720, 60, 13468, 74250, 220, 110, 20, 5, 40, 5, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED}, {1360, 768, 60, 11696, 85500, 256, 64, 17, 3, 112, 7, 0, FB_VMODE_NONINTERLACED}, {1920, 1080, 60, 6734, 148500, 148, 88, 36, 4, 44, 5, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED}, {1920, 1200, 60, 6494, 154000, 80, 48, 26, 3, 32, 6, FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED}, }; /************************************************************************ * Get Parameters for the video mode: */ /********************************************************************* * returns the length to the next seperator */ static int video_get_param_len(const char *start, char sep) { int i = 0; while ((*start != 0) && (*start != sep)) { start++; i++; } return i; } static int video_search_param (char *start, char *param) { int len, totallen, i; char *p = start; len = strlen (param); totallen = len + strlen (start); for (i = 0; i < totallen; i++) { if (strncmp (p++, param, len) == 0) return (i); } return -1; } /*************************************************************** * Get parameter via the environment as it is done for the * linux kernel i.e: * video=ctfb:x:800,xv:1280,y:600,yv:1024,depth:16,mode:0,pclk:25000, * le:56,ri:48,up:26,lo:5,hs:152,vs:2,sync:0,vmode:0,accel:0 * * penv is a pointer to the environment, containing the string, or the name of * another environment variable. It could even be the term "bootargs" */ #define GET_OPTION(name,var) \ if(strncmp(p,name,strlen(name))==0) { \ val_s=p+strlen(name); \ var=simple_strtoul(val_s, NULL, 10); \ } int video_get_params (struct ctfb_res_modes *pPar, char *penv) { char *p, *s, *val_s; int i = 0; int bpp; int mode; /* first search for the environment containing the real param string */ s = penv; p = env_get(s); if (p) s = p; /* * in case of the bootargs line, we have to start * after "video=ctfb:" */ i = video_search_param (s, "video=ctfb:"); if (i >= 0) { s += i; s += strlen ("video=ctfb:"); } /* search for mode as a default value */ p = s; mode = 0; /* default */ while ((i = video_get_param_len (p, ',')) != 0) { GET_OPTION ("mode:", mode) p += i; if (*p != 0) p++; /* skip ',' */ } if (mode >= RES_MODES_COUNT) mode = 0; *pPar = res_mode_init[mode]; /* copy default values */ bpp = 24 - ((mode % 3) * 8); p = s; /* restart */ while ((i = video_get_param_len (p, ',')) != 0) { GET_OPTION ("x:", pPar->xres) GET_OPTION ("y:", pPar->yres) GET_OPTION ("refresh:", pPar->refresh) GET_OPTION ("le:", pPar->left_margin) GET_OPTION ("ri:", pPar->right_margin) GET_OPTION ("up:", pPar->upper_margin) GET_OPTION ("lo:", pPar->lower_margin) GET_OPTION ("hs:", pPar->hsync_len) GET_OPTION ("vs:", pPar->vsync_len) GET_OPTION ("sync:", pPar->sync) GET_OPTION ("vmode:", pPar->vmode) GET_OPTION ("pclk:", pPar->pixclock) GET_OPTION ("pclk_khz:", pPar->pixclock_khz) GET_OPTION ("depth:", bpp) p += i; if (*p != 0) p++; /* skip ',' */ } return bpp; } /* * Parse the 'video-mode' environment variable * * Example: "video-mode=fslfb:1280x1024-32@60,monitor=dvi". See * doc/README.video for more information on how to set the variable. * * @xres: returned value of X-resolution * @yres: returned value of Y-resolution * @depth: returned value of color depth * @freq: returned value of monitor frequency * @options: pointer to any remaining options, or NULL * * Returns 1 if valid values were found, 0 otherwise */ int video_get_video_mode(unsigned int *xres, unsigned int *yres, unsigned int *depth, unsigned int *freq, const char **options) { char *p = env_get("video-mode"); if (!p) return 0; /* Skip over the driver name, which we don't care about. */ p = strchr(p, ':'); if (!p) return 0; /* Get the X-resolution*/ while (*p && !isdigit(*p)) p++; *xres = simple_strtoul(p, &p, 10); if (!*xres) return 0; /* Get the Y-resolution */ while (*p && !isdigit(*p)) p++; *yres = simple_strtoul(p, &p, 10); if (!*yres) return 0; /* Get the depth */ while (*p && !isdigit(*p)) p++; *depth = simple_strtoul(p, &p, 10); if (!*depth) return 0; /* Get the frequency */ while (*p && !isdigit(*p)) p++; *freq = simple_strtoul(p, &p, 10); if (!*freq) return 0; /* Find the extra options, if any */ p = strchr(p, ','); *options = p ? p + 1 : NULL; return 1; } /* * Parse the 'video-mode' environment variable using video_get_video_mode() * and lookup the matching ctfb_res_modes in res_mode_init. * * @default_mode: RES_MODE_##x## define for the mode to store in mode_ret * when 'video-mode' is not set or does not contain a valid mode * @default_depth: depth to set when 'video-mode' is not set * @mode_ret: pointer where the mode will be stored * @depth_ret: pointer where the depth will be stored * @options: pointer to any remaining options, or NULL */ void video_get_ctfb_res_modes(int default_mode, unsigned int default_depth, const struct ctfb_res_modes **mode_ret, unsigned int *depth_ret, const char **options) { unsigned int i, xres, yres, depth, refresh; *mode_ret = &res_mode_init[default_mode]; *depth_ret = default_depth; *options = NULL; if (!video_get_video_mode(&xres, &yres, &depth, &refresh, options)) return; for (i = 0; i < RES_MODES_COUNT; i++) { if (res_mode_init[i].xres == xres && res_mode_init[i].yres == yres && res_mode_init[i].refresh == refresh) { *mode_ret = &res_mode_init[i]; *depth_ret = depth; return; } } printf("video-mode %dx%d-%d@%d not available, falling back to %dx%d-%d@%d\n", xres, yres, depth, refresh, (*mode_ret)->xres, (*mode_ret)->yres, *depth_ret, (*mode_ret)->refresh); } /* * Find the named string option within the ',' separated options string, and * store its value in dest. * * @options: ',' separated options string * @name: name of the option to look for * @dest: destination buffer to store the value of the option in * @dest_len: length of dest * @def: value to store in dest if the option is not present in options */ void video_get_option_string(const char *options, const char *name, char *dest, int dest_len, const char *def) { const char *p = options; const int name_len = strlen(name); int i, len; while (p && (i = video_get_param_len(p, ',')) != 0) { if (strncmp(p, name, name_len) == 0 && p[name_len] == '=') { len = i - (name_len + 1); if (len >= dest_len) len = dest_len - 1; memcpy(dest, &p[name_len + 1], len); dest[len] = 0; return; } p += i; if (*p != 0) p++; /* skip ',' */ } strcpy(dest, def); } /* * Find the named integer option within the ',' separated options string, and * return its value. * * @options: ',' separated options string * @name: name of the option to look for * @def: value to return if the option is not present in options */ int video_get_option_int(const char *options, const char *name, int def) { const char *p = options; const int name_len = strlen(name); int i; while (p && (i = video_get_param_len(p, ',')) != 0) { if (strncmp(p, name, name_len) == 0 && p[name_len] == '=') return simple_strtoul(&p[name_len + 1], NULL, 10); p += i; if (*p != 0) p++; /* skip ',' */ } return def; } /** * Convert an EDID detailed timing to a struct ctfb_res_modes * * @param t The EDID detailed timing to be converted * @param mode Returns the converted timing * * @return 0 on success, or a negative errno on error */ int video_edid_dtd_to_ctfb_res_modes(struct edid_detailed_timing *t, struct ctfb_res_modes *mode) { int margin, h_total, v_total; /* Check all timings are non 0 */ if (EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) == 0 || EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*t) == 0 || EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t) == 0 || EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*t) == 0 || EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t) == 0 || EDID_DETAILED_TIMING_HSYNC_OFFSET(*t) == 0 || EDID_DETAILED_TIMING_VSYNC_OFFSET(*t) == 0 || /* 3d formats are not supported */ EDID_DETAILED_TIMING_FLAG_STEREO(*t) != 0) return -EINVAL; mode->xres = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*t); mode->yres = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*t); h_total = mode->xres + EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t); v_total = mode->yres + EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t); mode->refresh = EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) / (h_total * v_total); mode->pixclock_khz = EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) / 1000; mode->pixclock = 1000000000L / mode->pixclock_khz; mode->right_margin = EDID_DETAILED_TIMING_HSYNC_OFFSET(*t); mode->hsync_len = EDID_DETAILED_TIMING_HSYNC_PULSE_WIDTH(*t); margin = EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*t) - (mode->right_margin + mode->hsync_len); if (margin <= 0) return -EINVAL; mode->left_margin = margin; mode->lower_margin = EDID_DETAILED_TIMING_VSYNC_OFFSET(*t); mode->vsync_len = EDID_DETAILED_TIMING_VSYNC_PULSE_WIDTH(*t); margin = EDID_DETAILED_TIMING_VERTICAL_BLANKING(*t) - (mode->lower_margin + mode->vsync_len); if (margin <= 0) return -EINVAL; mode->upper_margin = margin; mode->sync = 0; if (EDID_DETAILED_TIMING_FLAG_HSYNC_POLARITY(*t)) mode->sync |= FB_SYNC_HOR_HIGH_ACT; if (EDID_DETAILED_TIMING_FLAG_VSYNC_POLARITY(*t)) mode->sync |= FB_SYNC_VERT_HIGH_ACT; if (EDID_DETAILED_TIMING_FLAG_INTERLACED(*t)) mode->vmode = FB_VMODE_INTERLACED; else mode->vmode = FB_VMODE_NONINTERLACED; return 0; } void video_ctfb_mode_to_display_timing(const struct ctfb_res_modes *mode, struct display_timing *timing) { timing->pixelclock.typ = mode->pixclock_khz * 1000; timing->hactive.typ = mode->xres; timing->hfront_porch.typ = mode->right_margin; timing->hback_porch.typ = mode->left_margin; timing->hsync_len.typ = mode->hsync_len; timing->vactive.typ = mode->yres; timing->vfront_porch.typ = mode->lower_margin; timing->vback_porch.typ = mode->upper_margin; timing->vsync_len.typ = mode->vsync_len; timing->flags = 0; if (mode->sync & FB_SYNC_HOR_HIGH_ACT) timing->flags |= DISPLAY_FLAGS_HSYNC_HIGH; else timing->flags |= DISPLAY_FLAGS_HSYNC_LOW; if (mode->sync & FB_SYNC_VERT_HIGH_ACT) timing->flags |= DISPLAY_FLAGS_VSYNC_HIGH; else timing->flags |= DISPLAY_FLAGS_VSYNC_LOW; if (mode->vmode == FB_VMODE_INTERLACED) timing->flags |= DISPLAY_FLAGS_INTERLACED; }