Commit 8368bee1 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

script: implement script_gpio_entry_append()

parent c62b4603
...@@ -126,6 +126,7 @@ void script_entry_delete(struct script_entry *entry) ...@@ -126,6 +126,7 @@ void script_entry_delete(struct script_entry *entry)
assert(entry); assert(entry);
assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD || assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD ||
entry->type == SCRIPT_VALUE_TYPE_STRING || entry->type == SCRIPT_VALUE_TYPE_STRING ||
entry->type == SCRIPT_VALUE_TYPE_GPIO ||
entry->type == SCRIPT_VALUE_TYPE_NULL); entry->type == SCRIPT_VALUE_TYPE_NULL);
if (!list_empty(&entry->entries)) if (!list_empty(&entry->entries))
...@@ -138,6 +139,9 @@ void script_entry_delete(struct script_entry *entry) ...@@ -138,6 +139,9 @@ void script_entry_delete(struct script_entry *entry)
case SCRIPT_VALUE_TYPE_STRING: case SCRIPT_VALUE_TYPE_STRING:
container = container_of(entry, struct script_string_entry, entry); container = container_of(entry, struct script_string_entry, entry);
break; break;
case SCRIPT_VALUE_TYPE_GPIO:
container = container_of(entry, struct script_gpio_entry, entry);
break;
case SCRIPT_VALUE_TYPE_NULL: case SCRIPT_VALUE_TYPE_NULL:
container = container_of(entry, struct script_null_entry, entry); container = container_of(entry, struct script_null_entry, entry);
break; break;
...@@ -207,3 +211,27 @@ struct script_string_entry *script_string_entry_append(struct script *script, ...@@ -207,3 +211,27 @@ struct script_string_entry *script_string_entry_append(struct script *script,
return entry; return entry;
} }
struct script_gpio_entry *script_gpio_entry_append(struct script *script,
const char *name,
unsigned port, unsigned num,
unsigned data[4])
{
struct script_gpio_entry *entry;
assert(script);
assert(!list_empty(&script->sections));
assert(name && *name);
if ((entry = malloc(sizeof(*entry)))) {
entry->port = port;
entry->port_num = num;
for (int i=0; i<4; i++)
entry->data[i] = data[i];
script_entry_append(script, &entry->entry,
SCRIPT_VALUE_TYPE_GPIO, name);
}
return entry;
}
...@@ -67,6 +67,14 @@ struct script_string_entry { ...@@ -67,6 +67,14 @@ struct script_string_entry {
char string[]; char string[];
}; };
/** entry describing a GPIO */
struct script_gpio_entry {
struct script_entry entry;
unsigned port, port_num;
unsigned data[4];
};
/** create a new script tree */ /** create a new script tree */
struct script *script_new(void); struct script *script_new(void);
/** deletes a tree recursively */ /** deletes a tree recursively */
...@@ -92,5 +100,10 @@ struct script_single_entry *script_single_entry_append(struct script *script, ...@@ -92,5 +100,10 @@ struct script_single_entry *script_single_entry_append(struct script *script,
struct script_string_entry *script_string_entry_append(struct script *script, struct script_string_entry *script_string_entry_append(struct script *script,
const char *name, const char *name,
size_t l, const char *s); size_t l, const char *s);
/** create a new GPIO entry appended to the last section of a tree */
struct script_gpio_entry *script_gpio_entry_append(struct script *script,
const char *name,
unsigned port, unsigned num,
unsigned data[4]);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment