zephyr/drivers/modem/modem_pin.c
Steven Slupsky b39423e0e2 drivers: modem: gpio api and string len
This commit references modem_pin() and modem_shell()

modem_pin(): use new gpio api
The existing pin driver does not respect gpio
configuration in device tree for active high / low
This commit allows for the device tree to determine the
active logic level.

modem_shell(): use correct string length
The ms_send macro uses iface.write() to send a string.
iface.write() requires the length of the string not the
size of the string.
This commit corrects the string length.

drivers: ublox-sara-r4: fix vint polling

This eliminates the implication that the enable and disable values can
be something other than 1 and 0, and fixes the code so it won't enter
an infinite loop if the GPIO read returns an error.

Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
2020-04-21 17:02:22 +03:00

70 lines
1.3 KiB
C

/** @file
* @brief Modem pin setup for modem context driver
*
* GPIO-based pin handling for the modem context driver
*/
/*
* Copyright (c) 2019 Foundries.io
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <device.h>
#include <drivers/gpio.h>
#include "modem_context.h"
int modem_pin_read(struct modem_context *ctx, u32_t pin)
{
if (pin >= ctx->pins_len) {
return -ENODEV;
}
return gpio_pin_get(ctx->pins[pin].gpio_port_dev,
ctx->pins[pin].pin);
}
int modem_pin_write(struct modem_context *ctx, u32_t pin, u32_t value)
{
if (pin >= ctx->pins_len) {
return -ENODEV;
}
return gpio_pin_set(ctx->pins[pin].gpio_port_dev,
ctx->pins[pin].pin, value);
}
int modem_pin_config(struct modem_context *ctx, u32_t pin, bool enable)
{
if (pin >= ctx->pins_len) {
return -ENODEV;
}
return gpio_pin_configure(ctx->pins[pin].gpio_port_dev,
ctx->pins[pin].pin,
enable ? ctx->pins[pin].init_flags :
GPIO_INPUT);
}
int modem_pin_init(struct modem_context *ctx)
{
int i, ret;
/* setup port devices and pin directions */
for (i = 0; i < ctx->pins_len; i++) {
ctx->pins[i].gpio_port_dev =
device_get_binding(ctx->pins[i].dev_name);
if (!ctx->pins[i].gpio_port_dev) {
return -ENODEV;
}
ret = modem_pin_config(ctx, i, true);
if (ret < 0) {
return ret;
}
}
return 0;
}