Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions include/objc/Application/Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

/**
* @file Application.h
* @brief Application framework header
* @defgroup Application Application Framework
* @ingroup objc
*
* Application-related classes and types, including application lifecycle,
* event handling, display and frames, and hardware interfaces.
*
* @example examples/Application/helloworld/main.m
*/
#pragma once
#include <Foundation/Foundation.h>
#include <runtime-hw/hw.h>

#if __OBJC__

// Forward Declaration of classes
@class Application;
@class GPIO;
@class NXInputManager;
@class NXTimer;

// Types and Enums
#import "NXApplication+Types.h"
#import "NXInputManager+Types.h"

// Protocols and Category Definitions
#include "ApplicationDelegate+Protocol.h"
#include "GPIODelegate+Protocol.h"
#include "InputManager+Protocols.h"
#include "TimerDelegate+Protocol.h"

// Class Definitions
#include "GPIO.h"
#include "LED.h"
#include "NXApplication.h"
#include "NXApplicationMain.h"
#include "NXTimer.h"

#endif // __OBJC__
83 changes: 83 additions & 0 deletions include/objc/Application/ApplicationDelegate+Protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @file ApplicationDelegate+Protocol.h
* @brief Defines a protocol for the application delegate.
*
* The ApplicationDelegate protocol defines methods that are called by the
* Application object at key moments in the application's lifecycle. By
* implementing these methods, objects can respond to application state
* changes and customize application behaviour.
*
* @example examples/Application/helloworld/main.m
* @example examples/Application/gpio/main.m
* @example examples/Application/timer/main.m
*/
#pragma once

/**
* @protocol ApplicationDelegate
* @ingroup Application
* @headerfile ApplicationDelegate+Protocol.h Application/Application.h
* @brief A protocol that defines the methods for an application delegate.
*
* The ApplicationDelegate protocol provides a way for objects to receive
* notifications about application lifecycle events. Classes that conform to
* this protocol can be set as the application's delegate to handle these
* events.
*/
@protocol ApplicationDelegate

@required

/**
* @brief Called when the application has finished launching.
* @param application The application instance that finished launching.
*
* This method is called once during the application's lifecycle, after
* the application has completed its initialization and is ready to begin
* processing events. This is the appropriate place to perform any final
* setup or initialization that your application requires.
*
* @note This method is called from the main run loop thread.
* @note The application's run loop will begin processing events after
* this method returns.
*/
- (void)applicationDidFinishLaunching:(id)application;

@optional

/**
* @brief Called immediately before the application terminates.
* @param application The application instance that is terminating.
*
* This method is called just before the application actually terminates.
* Use this method to perform any final cleanup tasks.
*/
- (void)applicationWillTerminate:(id)application;

/**
* @brief Called when the application receives a system signal.
* @param signal The type of signal that was received.
*
* This method is invoked when the application receives system signals such as
* termination requests (SIGTERM), interrupt signals (SIGINT/Ctrl+C), or quit
* signals (SIGQUIT). Implement this method to handle signals gracefully by
* performing cleanup operations, saving state, or initiating shutdown
* procedures.
*
* If this method is not implemented, the application will terminate
* with a -1 exit status when it receives a NXApplicationSignalTerm or
* NXApplicationSignalQuit signal. Other signals may be ignored.
*
* In the future, this method may be called for power management events,
* such as low or empty battery conditions, or sleep conditions, allowing
* applications to respond appropriately to changes in power status.
*
* @note This method may be called from a signal handler context on some
* platforms. Keep the implementation simple and avoid blocking operations,
* memory allocation, or complex system calls.
*
* @see NXApplicationSignal for available signal types.
*/
- (void)applicationReceivedSignal:(NXApplicationSignal)signal;

@end
142 changes: 142 additions & 0 deletions include/objc/Application/GPIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* @file GPIO.h
* @brief Defines a class for controlling General Purpose Input/Output (GPIO)
* pins.
*
* @example examples/Application/gpio/main.m
*/
#pragma once
#include <runtime-hw/hw.h>

///////////////////////////////////////////////////////////////////////////////
// CLASS DEFINITIONS

/**
* @brief The GPIO class
* @ingroup Application
* @headerfile GPIO.h Application/Application.h
*
* GPIO represents a class for controlling General Purpose Input/Output (GPIO)
* pins.
*
*/
@interface GPIO : NXObject {
@private
hw_gpio_t _pin; ///< Pointer to the GPIO data
}

/**
* @brief Returns a GPIO input instance.
* @param pin The GPIO pin number to configure as input.
* @return A new GPIO instance configured for input, or nil if the pin is
* invalid or initialization failed.
*
* This method creates a GPIO instance configured as a floating input pin.
* The pin will not have any internal pull-up or pull-down resistors enabled,
* so external circuitry should be used to ensure proper logic levels.
*
* @note The pin number must be valid for the target platform.
* @see pullupWithPin: for input with pull-up resistor
* @see pulldownWithPin: for input with pull-down resistor
*/
+ (GPIO *)inputWithPin:(uint8_t)pin;

/**
* @brief Returns a GPIO input instance, with pull-up resistor enabled.
* @param pin The GPIO pin number to configure as input with pull-up.
* @return A new GPIO instance configured for input with pull-up, or nil if the
* pin is invalid or initialization failed.
*
* This method creates a GPIO instance configured as an input pin with the
* internal pull-up resistor enabled. The pin will read as logical high (1)
* when not driven low by external circuitry.
*
* @note The pin number must be valid for the target platform.
* @see inputWithPin: for floating input
* @see pulldownWithPin: for input with pull-down resistor
*/
+ (GPIO *)pullupWithPin:(uint8_t)pin;

/**
* @brief Returns a GPIO input instance, with pull-down resistor enabled.
* @param pin The GPIO pin number to configure as input with pull-down.
* @return A new GPIO instance configured for input with pull-down, or nil if
* the pin is invalid or initialization failed.
*
* This method creates a GPIO instance configured as an input pin with the
* internal pull-down resistor enabled. The pin will read as logical low (0)
* when not driven high by external circuitry.
*
* @note The pin number must be valid for the target platform.
* @see inputWithPin: for floating input
* @see pullupWithPin: for input with pull-up resistor
*/
+ (GPIO *)pulldownWithPin:(uint8_t)pin;

/**
* @brief Returns a GPIO output instance.
* @param pin The GPIO pin number to configure as output.
* @return A new GPIO instance configured for output, or nil if the pin is
* invalid or initialization failed.
*
* This method creates a GPIO instance configured as an output pin.
* The initial state of the pin is platform-dependent and should be
* explicitly set using setState: after creation.
*
* @note The pin number must be valid for the target platform.
* @see setState: for controlling the output state
*/
+ (GPIO *)outputWithPin:(uint8_t)pin;

/**
* @brief Returns the total number of GPIO pins available.
* @return The total number of GPIO pins. Returns 0 if GPIO is not available.
*/
+ (uint8_t)count;

/**
* @brief Returns the pin number.
*/
- (uint8_t)pin;

/**
* @brief Returns true if the GPIO pin is configured as an input.
*/
- (bool)isInput;

/**
* @brief Returns true if the GPIO pin is configured as an output.
*/
- (bool)isOutput;

/**
* @brief Sets the delegate for GPIO events.
* @param delegate The delegate to set.
*
* This delegate will be notified of GPIO events, such as input changes.
* The delegate is not retained by the GPIO instance, so it must be
* retained by the caller. If called with nil, the current delegate will
* be removed.
*/
+ (void)setDelegate:(id<GPIODelegate>)delegate;

/**
* @brief Returns the current delegate for GPIO events.
* @return The current GPIO delegate, or nil if not set.
*/
+ (id<GPIODelegate>)delegate;

/**
* @brief Returns the state of the GPIO pin.
* @return true if the pin is high (logical 1), false if low (logical 0).
*/
- (BOOL)state;

/**
* @brief Sets the state of the GPIO pin.
* @param state true to set the pin high (logical 1), false to set low (logical
* 0).
*/
- (void)setState:(BOOL)state;

@end
33 changes: 33 additions & 0 deletions include/objc/Application/GPIODelegate+Protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file GPIODelegate+Protocol.h
* @brief Defines a protocol for the GPIO delegate.
*
* The GPIODelegate protocol defines methods that are called by the
* run loop when a GPIO event occurs.
*/
#pragma once
#include "GPIOTypes.h"

/**
* @protocol GPIODelegate
* @ingroup Application
* @headerfile GPIODelegate+Protocol.h Application/Application.h
* @brief A protocol that defines the methods for a GPIO delegate.
*/
@protocol GPIODelegate

@required

/**
* @brief Called when the GPIO input changes.
* @param sender The GPIO that triggered the event.
* @param event The event that occurred.
*
* This method is called when the GPIO input changes, either GPIOEventRising
* (from low to high) or GPIOEventFalling (from high to low). When both edges
* are detected, the event will include both GPIOEventRising and
* GPIOEventFalling (GPIOEventChanged).
*/
- (void)gpio:(id)sender changed:(GPIOEvent)event;

@end
20 changes: 20 additions & 0 deletions include/objc/Application/GPIOTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/**
* @file GPIOTypes.h
* @brief GPIO input types for handling GPIO events.
*
* GPIO-related types.
*/
#pragma once
#include <runtime-hw/hw.h>

/**
* @brief GPIO input types for handling GPIO events.
* @ingroup Application
*/
typedef enum {
GPIOEventRising = HW_GPIO_RISING, ///< Rising edge detected
GPIOEventFalling = HW_GPIO_FALLING, ///< Falling edge detected
GPIOEventChanged =
GPIOEventRising | GPIOEventFalling, ///< Both edges detected
} GPIOEvent;
Empty file.
Loading