Hall Switch  2.1.0
C++ library of Infineon single Hall-effect switch family for magnetic sensing applications
HallSwitch Class Reference

#include <hall-switch.hpp>

Inheritance diagram for HallSwitch:
Collaboration diagram for HallSwitch:

Classes

class  GPIO
 
class  Interrupt
 

Public Types

typedef void(* CBack_t) (Result_t)
 Callback function type for interrupt mode. More...
 
Error codes
enum  Error_t { OK = 0, INTF_ERROR = -1, CONF_ERROR = -2 }
 
Power modes
enum  PowerMode_t { MAIN = 1, SWITCH = 2 }
 
Status
enum  Status_t { UNINITED = 0, INITED = 1, POWER_ON = 2, POWER_OFF = 3 }
 
Measuring mode
enum  MeasMode_t { POLLING = 1, INTERRUPT = 2 }
 
Magnetic field value
enum  Result_t { B_FIELD_UNDEF = -1, B_FIELD_OFF = 0, B_FIELD_ON = 1 }
 

Public Member Functions

 HallSwitch ()
 Hall Switch Default Constructor. More...
 
 HallSwitch (GPIO *output, CBack_t cBack=NULL, GPIO *power=NULL)
 Hall Switch Constructor. More...
 
 ~HallSwitch ()
 Hall Switch Destructor Disables the sensor: More...
 
Error_t init ()
 Initializes the hardware interfaces. More...
 
Error_t deinit ()
 Deinitializes the hardware interfaces. More...
 
Error_t enable ()
 Enables the sensor. More...
 
Error_t disable ()
 Disables the sensor. More...
 
Status_t getStatus ()
 Gets the sensor status. More...
 
Error_t updateBField ()
 Updates instance magnetic field value. More...
 
Result_t getBField ()
 Gets magnetic field. More...
 

Protected Member Functions

virtual void callback ()
 Interrupt mode callback function. More...
 

Protected Attributes

Status_t status
 
GPIOoutput
 
Result_t bfieldVal
 
CBack_t cBack
 
MeasMode_t measMode
 
GPIOpower
 
PowerMode_t powerMode
 

Member Typedef Documentation

typedef void(* HallSwitch::CBack_t) (Result_t)

Callback function type for interrupt mode.

Parameters
[in]Result_tB field value. The interrupt read the B field value and will pass it to the callback
Returns
void

Member Enumeration Documentation

Enumerator
OK 

No error

INTF_ERROR 

Interface error

CONF_ERROR 

Configuration error

Enumerator
MAIN 

Same as MCU VDD supply signal

SWITCH 

Switched controlled power from MCU

Enumerator
UNINITED 

Not initialized

INITED 

Initialized (external interfaces initialized)

POWER_ON 

Power on

POWER_OFF 

Power off

Enumerator
POLLING 

Polling mode

INTERRUPT 

Interrupt mode

Enumerator
B_FIELD_UNDEF 

Output default high. Undefined at initialization

B_FIELD_OFF 

No magnetic field present. Off. Q output high

B_FIELD_ON 

Magnetic field present. On. Q output low

Constructor & Destructor Documentation

HallSwitch::HallSwitch ( )

Hall Switch Default Constructor.

  • Hardware interfaces pointers set to NULL
  • Default modes polling (for measure mode) and main (for switch power mode)
    Precondition
    None
HallSwitch::HallSwitch ( GPIO output,
CBack_t  cBack = NULL,
GPIO power = NULL 
)

Hall Switch Constructor.

Mandatory arguments:

  • Sensor output GPIO pointer

Optional arguments:

  • Interrupt callback. By default NULL. Required to enable interrupt mode.
  • Sensor power GPIO pointer (only for switch powered mode platform). By default it is NULL.
Parameters
[in]*outputSensor output GPIO interface pointer
[in]cBackCallback for interrupt mode. When passed, it enables interrupt mode
[in]*powerSensor switch power controller GPIO interface pointer. Default NULL will set power mode to MAIN
Precondition
None
HallSwitch::~HallSwitch ( )

Hall Switch Destructor Disables the sensor:

  • If "interrupt measuring mode" is enabled, the interrupt is disabled
  • If "switch power mode" is configured, the sensor power is disabled
    Precondition
    None

Here is the call graph for this function:

Member Function Documentation

HallSwitch::Error_t HallSwitch::init ( )

Initializes the hardware interfaces.

Precondition
None
Returns
HallSwitch error code
Return values
OKif success
INTF_ERRORif hardware interface error

Here is the call graph for this function:

HallSwitch::Error_t HallSwitch::deinit ( )

Deinitializes the hardware interfaces.

Precondition
Instance has called init()
Instance has called disable() if enable() was called
Returns
HallSwitch error code
Return values
OKif success
INTF_ERRORif hardware interface error

Here is the call graph for this function:

HallSwitch::Error_t HallSwitch::enable ( )

Enables the sensor.

  • If "switch power mode " is configured, the sensor is powered up
  • If "interrupt measuring mode" is configured, the interrupt is enabled
Precondition
Instance has called init()
Returns
HallSwitch error code
Return values
OKif success
INTF_ERRORif hardware interface error

Here is the call graph for this function:

HallSwitch::Error_t HallSwitch::disable ( )

Disables the sensor.

  • If the "interrupt measuring mode" is configured, the interrupt is disabled
  • If the "switch power mode" is configured, the sensor is powered off
Precondition
Instance has called enable()
Returns
HallSwitch error code
Return values
OKif success
INTF_ERRORif hardware interface error

Here is the call graph for this function:

HallSwitch::Status_t HallSwitch::getStatus ( )

Gets the sensor status.

Returns
HallSwitch status
HallSwitch::Error_t HallSwitch::updateBField ( )

Updates instance magnetic field value.

  • Magnetic field present if the GPIO voltage level is low
  • Mangnetic field not present if the GPIO voltage level is high

The "bfieldVal" object member is updated with the read GPIO value.

Precondition
Instance has called enable()
Returns
HallSwitch error code
Return values
OKif success
INTF_ERRORif hardware interface error

Here is the call graph for this function:

HallSwitch::Result_t HallSwitch::getBField ( )

Gets magnetic field.

This functions returns the last read value updated in the object member bfieldVal variable, either from a explicit updateBField() call or due to an interrupt event.

Precondition
If polling mode is used, updateBField() has to be called preivously in order to get the actual value.
Returns
HallSwitch Result_t magnetic field value
Return values
B_FIELD_ONif magnetic field present
B_FIELD_OFFif magnetic field NOT present
void HallSwitch::callback ( )
protectedvirtual

Interrupt mode callback function.

The instance updates on its own bfieldVal member when the interrupt occurs.

Additionally, the user callback function is executed.

Returns
void

Reimplemented in HallSpeed.

Here is the call graph for this function:

Member Data Documentation

Status_t HallSwitch::status
protected

Status

GPIO* HallSwitch::output
protected

Output GPIO hardware interface pointer

Result_t HallSwitch::bfieldVal
protected

Magnetic field value

CBack_t HallSwitch::cBack
protected

Interrupt mode callback function

MeasMode_t HallSwitch::measMode
protected

Measuring mode

GPIO* HallSwitch::power
protected

Power switch controller mode GPIO hardware interface pointer

PowerMode_t HallSwitch::powerMode
protected

Power mode


The documentation for this class was generated from the following files: