FRDM-IMX93 for NXP CUP
FRDM-IMX93 support for NXP CUP
 
Loading...
Searching...
No Matches
hbridge.h File Reference

L298N H-BRIDGE API definition. More...

#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pwm.h>

Go to the source code of this file.

Classes

struct  nxp_hbridge
 Represents the L298N H-BRIDGE module. More...
 

Macros

#define NXP_HBRIDGE_NUM_GPIOS   2
 
#define NXP_HBRIDGE_MAX_SPEED   100
 
#define NXP_HBRIDGE_MOTOR_INVERT   BIT(0)
 

Enumerations

enum  nxp_hbridge_direction { NXP_HBRIDGE_DIRECTION_OFF = 0 , NXP_HBRIDGE_DIRECTION_FORWARD = 1 , NXP_HBRIDGE_DIRECTION_BACKWARDS = 2 }
 Represents the spinning direction of a motor. More...
 

Functions

int nxp_hbridge_init (struct nxp_hbridge *hbridge)
 Initialize the L298 H-BRIDGE module.
 
int nxp_hbridge_set_direction (struct nxp_hbridge *hbridge, int direction)
 Set the spinning direction of the car's motors.
 
int nxp_hbridge_set_speed (struct nxp_hbridge *hbridge, uint32_t speed)
 Set the speed of the car's motors.
 

Detailed Description

L298N H-BRIDGE API definition.

This file offers the API required for working with the L298N H-BRIDGE module.

Macro Definition Documentation

◆ NXP_HBRIDGE_MAX_SPEED

#define NXP_HBRIDGE_MAX_SPEED   100

maximum allowed speed

◆ NXP_HBRIDGE_NUM_GPIOS

#define NXP_HBRIDGE_NUM_GPIOS   2

maximum number of GPIOs per motor

Enumeration Type Documentation

◆ nxp_hbridge_direction

Represents the spinning direction of a motor.

Enumerator
NXP_HBRIDGE_DIRECTION_OFF 

motor is stopped/braking

NXP_HBRIDGE_DIRECTION_FORWARD 

motor is spinning forward

NXP_HBRIDGE_DIRECTION_BACKWARDS 

motor is spinning backwards

Function Documentation

◆ nxp_hbridge_init()

int nxp_hbridge_init ( struct nxp_hbridge hbridge)

Initialize the L298 H-BRIDGE module.

Put the L298 H-BRIDGE hardware into a known state. This consists of:

  • ENA and ENB pins set to logic HIGH.
  • IN1, IN2, IN3, and IN4 pins set to logic LOW.
Parameters
hbridgepointer to structure representing the H-BRIDGE
Return values
0on success
negativeerrno code if failure

◆ nxp_hbridge_set_direction()

int nxp_hbridge_set_direction ( struct nxp_hbridge hbridge,
int  direction 
)

Set the spinning direction of the car's motors.

Parameters
hbridgepointer to the structure representing the H-BRIDGE
directionone of nxp_hbridge_direction
Return values
0on success
negativeerrno code if failure

◆ nxp_hbridge_set_speed()

int nxp_hbridge_set_speed ( struct nxp_hbridge hbridge,
uint32_t  speed 
)

Set the speed of the car's motors.

Set the speed of the car's motors based on a given percentage, where:

  • 0% means no speed (i.e. car is stopped/braking)
  • 100% means full speed
Parameters
hbridgepointer to the structure representing the H-BRIDGE
speedpercentage to set (from 0% to 100%)
Return values
0on success
negativeerrno code if failure