|
| 1 | +/**************************************************************************** |
| 2 | + * boards/arm/rp2040/common/src/rp2040_ads7046.c |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +/**************************************************************************** |
| 24 | + * Included Files |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +#include <nuttx/config.h> |
| 28 | + |
| 29 | +#include <stdio.h> |
| 30 | +#include <debug.h> |
| 31 | + |
| 32 | +#include <nuttx/arch.h> |
| 33 | +#include <nuttx/analog/ads7046.h> |
| 34 | + |
| 35 | +#include "rp2040_spi.h" |
| 36 | +#include "rp2040_ads7046.h" |
| 37 | + |
| 38 | +/**************************************************************************** |
| 39 | + * Pre-processor Definitions |
| 40 | + ****************************************************************************/ |
| 41 | + |
| 42 | +/**************************************************************************** |
| 43 | + * Private Types |
| 44 | + ****************************************************************************/ |
| 45 | + |
| 46 | +/**************************************************************************** |
| 47 | + * Private Function Prototypes |
| 48 | + ****************************************************************************/ |
| 49 | + |
| 50 | +/**************************************************************************** |
| 51 | + * Private Data |
| 52 | + ****************************************************************************/ |
| 53 | + |
| 54 | +/**************************************************************************** |
| 55 | + * Public Data |
| 56 | + ****************************************************************************/ |
| 57 | + |
| 58 | +/**************************************************************************** |
| 59 | + * Private Functions |
| 60 | + ****************************************************************************/ |
| 61 | + |
| 62 | +/**************************************************************************** |
| 63 | + * Public Functions |
| 64 | + ****************************************************************************/ |
| 65 | + |
| 66 | +/**************************************************************************** |
| 67 | + * Name: board_ads7046_initialize |
| 68 | + * |
| 69 | + * Description: |
| 70 | + * Initialize and register the ADS7046 ADC driver. |
| 71 | + * |
| 72 | + * Input Parameters: |
| 73 | + * spi - An instance of the SPI interface to use. |
| 74 | + * devno - The device number, used to build the device path as /dev/adcN. |
| 75 | + * |
| 76 | + * Returned Value: |
| 77 | + * Zero (OK) on success; a negated errno value on failure. |
| 78 | + * |
| 79 | + ****************************************************************************/ |
| 80 | + |
| 81 | +int board_ads7046_initialize(FAR struct spi_dev_s *spi, int devno) |
| 82 | +{ |
| 83 | + char devpath[10]; |
| 84 | + int ret; |
| 85 | + |
| 86 | + ainfo("Initializing ADS7046 #%d\n", devno); |
| 87 | + |
| 88 | + if (spi) |
| 89 | + { |
| 90 | + snprintf(devpath, sizeof(devpath), "/dev/adc%d", devno); |
| 91 | + ret = ads7046_register(devpath, spi, devno); |
| 92 | + if (ret < 0) |
| 93 | + { |
| 94 | + snerr("ERROR: Error registering ADS7046 at /dev/adc%d\n", devno); |
| 95 | + } |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + ret = -ENODEV; |
| 100 | + } |
| 101 | + |
| 102 | + return ret; |
| 103 | +} |
0 commit comments