boards/arm/imxrt/teensy-4.x: added support for encoder
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
parent
7bcd50955f
commit
0851036ae3
@ -98,6 +98,16 @@ selecting ``CONFIG_TEENSY_40=y``.
|
||||
This configuration runs over LPUART1 (pins 24 and 25 on Teensy). Communication
|
||||
over USB console can be turn on, but it causes problems with FlexCAN.
|
||||
|
||||
enc-4.1
|
||||
-------
|
||||
|
||||
This is an nsh configuration (see above) with added support of incremental
|
||||
encoder. Phase A is connected to GPIO_EMC_07 (pin 33), phase B to GPIO_EMC_06
|
||||
(pin 4) and INDEX to GPIO_B0_12 (pin 32). Only encoder 1 is connected to those
|
||||
pins.
|
||||
|
||||
Function of the encoder can be tested by application "qe".
|
||||
|
||||
netnsh-4.1
|
||||
----------
|
||||
|
||||
|
49
boards/arm/imxrt/teensy-4.x/configs/enc-4.1/defconfig
Normal file
49
boards/arm/imxrt/teensy-4.x/configs/enc-4.1/defconfig
Normal file
@ -0,0 +1,49 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="teensy-4.x"
|
||||
CONFIG_ARCH_BOARD_TEENSY_4X=y
|
||||
CONFIG_ARCH_CHIP="imxrt"
|
||||
CONFIG_ARCH_CHIP_IMXRT=y
|
||||
CONFIG_ARCH_CHIP_MIMXRT1062DVL6A=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARMV7M_DCACHE=y
|
||||
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
|
||||
CONFIG_ARMV7M_ICACHE=y
|
||||
CONFIG_ARMV7M_USEBASEPRI=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=104926
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_ENC1_XIP=y
|
||||
CONFIG_EXAMPLES_QENCODER=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||
CONFIG_IMXRT_ENC1=y
|
||||
CONFIG_IMXRT_LPUART1=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_IOB_NBUFFERS=24
|
||||
CONFIG_IOB_NCHAINS=24
|
||||
CONFIG_LPUART1_SERIAL_CONSOLE=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_IOB=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_RAM_SIZE=1048576
|
||||
CONFIG_RAM_START=0x20200000
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SENSORS=y
|
||||
CONFIG_SENSORS_QENCODER=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_START_DAY=14
|
||||
CONFIG_START_MONTH=3
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TEENSY_41=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WQUEUE_NOTIFIER=y
|
@ -58,4 +58,8 @@ ifeq ($(CONFIG_LCD_ST7789),y)
|
||||
CSRCS += imxrt_st7789.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_IMXRT_ENC),y)
|
||||
CSRCS += imxrt_enc.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/boards/Board.mk
|
||||
|
@ -183,6 +183,16 @@ int imxrt_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMXRT_ENC
|
||||
/* Initialize ENC and register the ENC driver. */
|
||||
|
||||
ret = imxrt_enc_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: imxrt_enc_initialize() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
133
boards/arm/imxrt/teensy-4.x/src/imxrt_enc.c
Normal file
133
boards/arm/imxrt/teensy-4.x/src/imxrt_enc.c
Normal file
@ -0,0 +1,133 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/imxrt/teensy-4.x/src/imxrt_enc.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/sensors/qencoder.h>
|
||||
|
||||
#include "imxrt_enc.h"
|
||||
#include "imxrt_xbar.h"
|
||||
#include "teensy-4.h"
|
||||
|
||||
#if defined(CONFIG_IMXRT_ENC) && defined(CONFIG_SENSORS_QENCODER)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imxrt_enc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the quadrature encoder driver for the given timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int imxrt_enc_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
#ifdef CONFIG_IMXRT_ENC1
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
imxrt_config_gpio(GPIO_ENC1_PHASE_A);
|
||||
imxrt_config_gpio(GPIO_ENC1_PHASE_B);
|
||||
imxrt_config_gpio(GPIO_ENC1_INDEX);
|
||||
|
||||
/* Connect XBAR pins */
|
||||
|
||||
ret = imxrt_xbar_connect(IMXRT_XBARA1_OUT_ENC1_PHASE_AIN_SEL_OFFSET,
|
||||
IMXRT_XBARA1_IN_IOMUX_XBAR_IO09);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_xbar_connect failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = imxrt_xbar_connect(IMXRT_XBARA1_OUT_ENC1_PHASE_BIN_SEL_OFFSET,
|
||||
IMXRT_XBARA1_IN_IOMUX_XBAR_IO08);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_xbar_connect failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = imxrt_xbar_connect(IMXRT_XBARA1_OUT_ENC1_INDEX_SEL_OFFSET,
|
||||
IMXRT_XBARA1_IN_IOMUX_XBAR_IO10);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_xbar_connect failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = imxrt_qeinitialize("dev/qe0", 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_qeinitialize failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_ENC2
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
ret = imxrt_qeinitialize("dev/qe1", 2)
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_qeinitialize failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_ENC3
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
ret = imxrt_qeinitialize("dev/qe2", 3)
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_qeinitialize failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef CONFIG_IMXRT_ENC4
|
||||
/* Initialize a quadrature encoder interface. */
|
||||
|
||||
ret = imxrt_qeinitialize("dev/qe4", 4)
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: imxrt_qeinitialize failed: %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
#endif /* CONFIG_IMXRT_ENC */
|
@ -35,6 +35,7 @@
|
||||
|
||||
# include "imxrt_gpio.h"
|
||||
# include "imxrt_iomuxc.h"
|
||||
# include "hardware/imxrt_pinmux.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -111,6 +112,12 @@
|
||||
#define GPIO_ENET_RST (GPIO_OUTPUT | GPIO_OUTPUT_ZERO | \
|
||||
GPIO_PORT2 | GPIO_PIN14 | IOMUX_ENET_RST_DEFAULT) /* B0_14 */
|
||||
|
||||
/* Quadrature Encoder */
|
||||
|
||||
#define GPIO_ENC1_PHASE_A (GPIO_XBAR1_INOUT09_1|IOMUX_ENC_DEFAULT|PADMUX_MUXMODE_ALT3) /* EMC_07 */
|
||||
#define GPIO_ENC1_PHASE_B (GPIO_XBAR1_INOUT08_1|IOMUX_ENC_DEFAULT|PADMUX_MUXMODE_ALT3) /* EMC_06 */
|
||||
#define GPIO_ENC1_INDEX (GPIO_XBAR1_INOUT10_1|IOMUX_ENC_DEFAULT|PADMUX_MUXMODE_ALT1) /* B0_12 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@ -167,6 +174,18 @@ int imxrt_can_setup(void);
|
||||
int imxrt_adc_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imxrt_enc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the quadrature encoder driver for the given timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_IMXRT_ENC
|
||||
int imxrt_enc_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imxrt_i2c_setup
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user